I have an XSLT which i use to transform an XML using Java. The code is working fine when i run it in eclipse and use Apache Tomcat. But when i deploy the ear file to WebSphere, the field is showing as blank. Does anyone have ideas?
The java variables 'reportId' and 'proposalId' are set as i used System.out.println() and could see the value is set.
Java Code // Use the factory to create a template containing the xsl file
Templates template = factory.newTemplates(new StreamSource(is));
// Use the template to create a transformer
Transformer xformer = template.newTransformer();
xformer.setParameter("reportId", reportId);
xformer.setParameter("proposalId", proposalId);
<xsl:param name="proposalId"/>
<xsl:param name="reportId"/>
I then use the following in the XSLT to read the parameter:
<td align="left"><b>Proposal Ref: </b> <xsl:value-of select="$proposalId"/>
</td>
<td align="left"><b>Report Id: </b> <xsl:value-of select="$reportId"/>
</td>
I found that i had the param inside the template tag. The transformer can not set the value of a template level variable. It can only set it on a global level variable. So my code was like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:param name="proposalId"/>
<xsl:param name="reportId"/>
</xsl:template>
</xsl:stylesheet>
but it should have been:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:param name="proposalId"/>
<xsl:param name="reportId"/>
<xsl:template match="/">
</xsl:template>
</xsl:stylesheet>