Transform using XSL 2.0 with JAXP

Hi,

I am transforming a xml file to a jsp using xsl. I am shifting from xsl 1.0 to 2.0.

I tried to use the "character-maps" functionality available in xsl "2.0".

I expected the below xsl code:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">

<xsl:output method="html" encoding="UTF-16" indent="yes" use-character-maps="cMaps"/>

<xsl:character-map name="cMaps">

<xsl:output-character character="? string="&lt;%"/>

<xsl:output-character character="? string="%&gt;"/>

</xsl:character-map>

<xsl:template match="/">

<xsl:text>?lt;/xsl:text>

</xsl:template>

</xsl:stylesheet>

To generate the following:

<% %>

The expected transformation of character-maps does not work when I use "javax.xml.transform" package for transformation.

Following is the piece of code which I use for transformation

try {

javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance();

javax.xml.transform.Transformer transformer = tFactory.newTransformer(stXsl);

transformer.transform(stInput, srOutput);

catch (Exception ex) {

}

The above transformation generates?/i>

The xsl seems to be correct as I get the expected output when I use XML Spy.

Do I need to something more in my java code for using xsl 2.0.

Regards

Anup

[1737 byte] By [akallia] at [2007-11-27 7:02:52]
# 1

> Do I need to something more in my java code for using xsl 2.0.

Yes. You need to tell it to use a transformer that supports XSLT 2.0. The transformer built into Java does not, so you have to do something specific.

First find an XSLT 2.0 compliant transformer. I know that Saxon is one such, possibly there are others. Then follow the instructions in their documentation that explain how to make JAXP use their product for transforming.

DrClapa at 2007-7-12 18:53:59 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...