A NullPointerException occurring within the code of your XSLT processor is a
bug, and should be notified to the vendor.
The free-standing version of Xalan is reputed to be more reliable than the
one bundled with JDK 1.4.
Michael Kay
-----Original Message-----
From: Paolo Noya [mailto:paolo(_dot_)noya(_at_)fullsix(_dot_)com]
Sent: 10 September 2004 16:20
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Sort problem
Hi,
I've a problem during sort node with xalan-j version
2.4.1(bundle with jdk 1.4.2_05).
I have an XML like this:
=======================
<?xml version="1.0"?>
<Peoples>
<Person>
<Name>Johnson</Name>
<Level>foo</Level>
</Person>
<Person>
<Name>Smith</Name>
<Level>baz</Level>
</Person>
<Person>
<Name>White</Name>
<Level>foo</Level>
</Person>
<Person>
<Name>Brown</Name>
</Person>
<Person>
<Name>Black</Name>
<Level>bar</Level>
</Person>
</Peoples>
=======================
and I want sort by level and then by name giving a rule for
mapping level with an arbitrary number.
I wrote an xml like this:
=======================
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:this="http://localhost/" exclude-result-prefixes="this"
<this:Levels>
<Level pos="0"/><!--dummy level-->
<Level pos="1">foo</Level>
<Level pos="2">bar</Level>
<Level pos="3">baz</Level>
</this:Levels>
<xsl:variable name="levels"
select="document('')/xsl:stylesheet/this:Levels"/>
<xsl:template match="/Peoples">
<xsl:apply-templates select="Person">
<xsl:sort data-type="number"
select="number($levels/Level[.=current()/Level]/@pos)"/>
<xsl:sort select="Name"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Person">
<xsl:value-of select="Name"/><br/>
</xsl:template>
</xsl:stylesheet>
=======================
during transfom, the element <xsl:sort data-type="number"
select="number($levels/Level[.=current()/Level]/@pos)"/>
produce an excepiton
javax.xml.transform.TransformerException:
java.lang.NullPointerException
but if i print the <xsl:value-of
select="number($levels/Level[.=current()/Level]/@pos)"/> in
"Person" template I got the correct value.
If apply the same transform directly with my IE6.0 (so using
msxml transformer) i obtain the correct result.
What's wrong?
It is my error suppose that the current() function inside
sort element refer to selected node in apply-templates?
regards,
Paolo