You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by damien <da...@dwl.co.uk> on 2001/03/19 16:40:50 UTC
Problem with namespaces?
Hi...
I am trying to get a JSP to convert XML into HTML by using the Xalan
processor and an
Apache-Tomcat set up to handle requests for my JSP. The problem that I'm
having centers
around an error message which states:
"TransformerConfigurationException: Namespace not supported by SAXParser"
(I'm using the javax.xml.transform.* package)
The TrAX documentation mentions that there are problems with namespaces or
"qualified
name representation", but its not clear (at least not to me) how to
implement a workaround.
Basically I'm looking to try and get Apache to serve xml documents. I would
appreciate any
help on this matter.
I am using the following to produce this error:
Stocks.xml:
<?xml version="1.0"?>
<portfolio xmlns:dt="urn:schemas-microsoft-com:datatypes">
<stock exchange="nyse">
<name>zacx corp</name>
<symbol>ZCXM</symbol>
<price dt:dt="number">28.875</price>
</stock>
<stock exchange="nasdaq">
<name>zaffymat inc</name>
<symbol>ZFFX</symbol>
<price dt:dt="number">92.250</price>
</stock>
<stock exchange="nasdaq">
<name>zysmergy inc</name>
<symbol>ZYSZ</symbol>
<price dt:dt="number">20.313</price>
</stock>
<stock>
<name>zdfunkt corp</name>
<symbol>ZDKT</symbol>
<price dt:dt="number">77.011</price>
</stock>
</portfolio>
Stocks.xsl:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<body>
<table border="2" cellPadding="2" cellSpacing="0">
<tr>
<td>Symbol</td>
<td>Name</td>
<td>Price</td>
</tr>
<xsl:for-each select="portfolio/stock[@exchange = 'nasdaq']">
<tr>
<xsl:attribute name="title"><xsl:value-of select="symbol"/>
is listed on the <xsl:value-of select="@exchange"/>
stock exchange.</xsl:attribute>
<td><xsl:value-of select="symbol"/></td>
<xsl:apply-templates select="name" />
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="name">
<td style="font-family: tahoma; background-color:#0088ff; color:#ffffff">
<xsl:apply-templates />
</td>
</xsl:template>
</xsl:stylesheet>
xml to html JSP:
<%@ page import="javax.xml.transform.*" %>
<%@ page import="javax.xml.transform.stream.*" %>
<%
String xmlFileName = request.getParameter("xml");
String xslFileName = request.getParameter("xsl");
if (xmlFileName != null && xslFileName != null) {
try{
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new
StreamSource(xslFileName); //falls over here!!!
transformer.transform(new StreamSource(xmlFileName), new
StreamResult(out));
} catch(TransformerException e) {
out.println(xmlFileName + "<br/>");
out.println(xslFileName + "<br/>");
out.println(e.toString()); }
} else {
%>
<html>
<head>
<title>XML to HTML error</title>
</head>
<body>
<h1>XML to HTML error</h1>
XML and XSL are required parameters to this servlet!
</body>
</html>
<%
}
%>
The URL I use to call the JSP looks something like:
http://localhost/jsp/xml/xml2html.jsp?xml=stocks.xml&xsl=stocks.xsl
Regards,
Damien
Re: Problem with namespaces?
Posted by Christopher Farley <ch...@northernbrewer.com>.
damien (damien_abrahams@dwl.co.uk) wrote:
> Hi...
>
> I am trying to get a JSP to convert XML into HTML by using the Xalan
> processor and an
> Apache-Tomcat set up to handle requests for my JSP. The problem that I'm
> having centers
> around an error message which states:
>
> "TransformerConfigurationException: Namespace not supported by SAXParser"
> (I'm using the javax.xml.transform.* package)
I believe this is a Tomcat problem; Tomcat exposes its jaxp-compliant
xml parser to the java classes that run under it.
The workaround is to replace Tomcat's jaxp.jar and parser.jar in
$TOMCAT_HOME/lib with xerces.jar and xalan.jar.
The Tomcat people are aware of this issue, and apparantly it works
properly in the upcoming 4.0 release.
--
Christopher Farley
www.northernbrewer.com
Re: Problem with namespaces?
Posted by Rick Knowles <ri...@cheapanet.com.au>.
I run the same setup, doing the same thing you mentioned.
The problem is that Tomcat puts jaxp ahead of xerces in its classpath. You
need to edit tomcat.sh/tomcat.bat and change it so the system classpath is
added before the tomcat classpath.
R
----- Original Message -----
From: "damien" <da...@dwl.co.uk>
To: <xa...@xml.apache.org>
Sent: Tuesday, March 20, 2001 2:40 AM
Subject: Problem with namespaces?
> Hi...
>
> I am trying to get a JSP to convert XML into HTML by using the Xalan
> processor and an
> Apache-Tomcat set up to handle requests for my JSP. The problem that I'm
> having centers
> around an error message which states:
>
> "TransformerConfigurationException: Namespace not supported by SAXParser"
> (I'm using the javax.xml.transform.* package)
>
> The TrAX documentation mentions that there are problems with namespaces or
> "qualified
> name representation", but its not clear (at least not to me) how to
> implement a workaround.
> Basically I'm looking to try and get Apache to serve xml documents. I
would
> appreciate any
> help on this matter.
>
> I am using the following to produce this error:
>
> Stocks.xml:
> <?xml version="1.0"?>
> <portfolio xmlns:dt="urn:schemas-microsoft-com:datatypes">
> <stock exchange="nyse">
> <name>zacx corp</name>
> <symbol>ZCXM</symbol>
> <price dt:dt="number">28.875</price>
> </stock>
> <stock exchange="nasdaq">
> <name>zaffymat inc</name>
> <symbol>ZFFX</symbol>
> <price dt:dt="number">92.250</price>
> </stock>
> <stock exchange="nasdaq">
> <name>zysmergy inc</name>
> <symbol>ZYSZ</symbol>
> <price dt:dt="number">20.313</price>
> </stock>
> <stock>
> <name>zdfunkt corp</name>
> <symbol>ZDKT</symbol>
> <price dt:dt="number">77.011</price>
> </stock>
> </portfolio>
>
> Stocks.xsl:
> <?xml version='1.0'?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:template match="/">
> <html>
> <body>
> <table border="2" cellPadding="2" cellSpacing="0">
> <tr>
> <td>Symbol</td>
> <td>Name</td>
> <td>Price</td>
> </tr>
> <xsl:for-each select="portfolio/stock[@exchange = 'nasdaq']">
> <tr>
> <xsl:attribute name="title"><xsl:value-of select="symbol"/>
> is listed on the <xsl:value-of select="@exchange"/>
> stock exchange.</xsl:attribute>
> <td><xsl:value-of select="symbol"/></td>
> <xsl:apply-templates select="name" />
> <td><xsl:value-of select="price"/></td>
> </tr>
> </xsl:for-each>
> </table>
> </body>
> </html>
> </xsl:template>
> <xsl:template match="name">
> <td style="font-family: tahoma; background-color:#0088ff; color:#ffffff">
> <xsl:apply-templates />
> </td>
> </xsl:template>
> </xsl:stylesheet>
>
> xml to html JSP:
> <%@ page import="javax.xml.transform.*" %>
> <%@ page import="javax.xml.transform.stream.*" %>
>
> <%
> String xmlFileName = request.getParameter("xml");
> String xslFileName = request.getParameter("xsl");
>
> if (xmlFileName != null && xslFileName != null) {
> try{
> TransformerFactory tFactory = TransformerFactory.newInstance();
> Transformer transformer = tFactory.newTransformer(new
> StreamSource(xslFileName); //falls over here!!!
> transformer.transform(new StreamSource(xmlFileName), new
> StreamResult(out));
> } catch(TransformerException e) {
> out.println(xmlFileName + "<br/>");
> out.println(xslFileName + "<br/>");
> out.println(e.toString()); }
> } else {
> %>
> <html>
> <head>
> <title>XML to HTML error</title>
> </head>
> <body>
> <h1>XML to HTML error</h1>
> XML and XSL are required parameters to this servlet!
> </body>
> </html>
> <%
> }
> %>
>
> The URL I use to call the JSP looks something like:
> http://localhost/jsp/xml/xml2html.jsp?xml=stocks.xml&xsl=stocks.xsl
>
>
> Regards,
>
> Damien
>