Hi,
I am using WSAD5 to write a xsl stylesheet that is using xalan extension
function "xalan:nodeset". it runs correctly under "Websphere v5.0 test
environment" and IDE environment, but gets an unexpected result under
"Websphere v4.0 test environment" (I attached the xml, xsl, jsp and result
files below). I notice that these two test environments use different
versions of XALAN (1.2.2 for v4 and 2.3.4 for v5). It seems that XALAN 1.2.2
confuses with "child" and "descendant" once "xalan:nodeset" is used. My
questions are:
1. Did anyone have this problem before? Is there any work-around if we need
to keep using the old version of XALAN?
2. How to upgrade XALAN to the newer version for WAS v4 test environment. I
tried to add jar files to "ws.ext.dirs" in server configuration, but it is
still not working.
Thanks in advance.
Xiang Wu
xml file:
<?xml version="1.0" encoding="UTF-8"?>
<test>
<person>
<first>J<font color="red">oh</font>n</first>
<last>Doe</last>
</person>
</test>
xsl file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan"
>
<xsl:template match="/">
<html>
<body>
<xsl:variable name="name">
<xsl:apply-templates select="/test/person/last"/>
<xsl:apply-templates select="/test/person/first"/>
</xsl:variable>
<p>
<xsl:call-template
name="listToTextSeperatedByDelimiterWithoutWrapperElement">
<xsl:with-param name="list" select="xalan:nodeset($name)/*"/>
<xsl:with-param name="delimiter" select="','"/>
</xsl:call-template>
</p>
</body>
</html>
</xsl:template>
<!-- convert a list of element into a text (inheriting all child elements)
-->
<xsl:template name="listToTextSeperatedByDelimiterWithoutWrapperElement">
<xsl:param name="list"/>
<xsl:param name="delimiter"/>
<xsl:for-each select="$list[normalize-space(.)]">
<xsl:apply-templates/>
<xsl:choose>
<xsl:when test="position() = last()"/> <!-- do nothing -->
<xsl:otherwise>
<xsl:value-of select="concat(normalize-space($delimiter), ' ')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!-- deep copy -->
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Jsp file:
<%@ page import="java.io.File" %>
<%@ page import="javax.xml.transform.TransformerFactory" %>
<%@ page import="javax.xml.transform.Transformer" %>
<%@ page import="javax.xml.transform.stream.StreamSource" %>
<%@ page import="javax.xml.transform.stream.StreamResult" %>
<%
File xmlFile = new File("testcopy.xml");
File xslFile = new File("testcopy_nodeset.xsl");
try {
//Get the transformer
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer (new
StreamSource(xslFile));
transformer.transform ( new StreamSource(xmlFile), new
StreamResult(response.getWriter()) );
} catch (Exception ex) {
ex.printStackTrace();
throw new ServletException(ex);
}
%>
result in WAS v4 test env
<html>
<body>
<p>Doe, J<font color="red">oh</font>n, oh</p>
</body>
</html>
result in WAS v5 test env
<html>
<body>
<p>Doe, J<font color="red">oh</font>n</p>
</body>
</html>
|