[xsl] two-phase transformation fails to match with expected template.

Subject: [xsl] two-phase transformation fails to match with expected template.
From: Jeroen Hellingman <jeroen@xxxxxxxx>
Date: Tue, 24 Nov 2009 22:43:41 +0100
I am trying to do a two-phase transformation in the following stylesheet (stripped to show the issue), adding some more attributes in the second phase, which would be fairly difficult to calculate correctly at once. However, the template adding the attribute seems not to fire at all.
(I expect my navPoint elements to get an additional playorder attribute.) (Using Saxon HE 9)


Am I overlooking something?

Would the xsl:number work in the context of the variable, or of the input document?


<?xml version="1.0" encoding="ISO-8859-1"?>


   <xsl:stylesheet
       xmlns="http://www.w3.org/1999/xhtml";
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
       version="2.0">

   <xsl:output
       doctype-public="-//W3C//DTD XHTML 1.1//EN"
       doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";
       method="xml"
       encoding="UTF-8"/>

<xsl:template match="/">
<xsl:variable name="test">
<html>
<navPoint class="section" id="xd21e491">
<navLabel>
<text>Test 1</text>
</navLabel>
<content src="test-ch05.xhtml#xd21e491"/>
</navPoint>
<navPoint class="section" id="xd21e491">
<navLabel>
<text>Test 2</text>
</navLabel>
<content src="test-ch05.xhtml#xd21e491"/>
</navPoint>
</html>
</xsl:variable>
<xsl:apply-templates select="$test" mode="playorder"/>
</xsl:template>
<xsl:template match="text" mode="playorder"/>


<xsl:template match="navPoint" mode="playorder">
<xsl:copy>
<xsl:attribute name="playOrder"><xsl:number level="any" count="navPoint"/></xsl:attribute>
<xsl:apply-templates select="@*|node()" mode="playorder"/>
</xsl:copy>
</xsl:template>


   <xsl:template match="@*|node()" mode="playorder">
       <xsl:copy>
           <xsl:apply-templates select="@*|node()" mode="playorder"/>
       </xsl:copy>
   </xsl:template>

</xsl:stylesheet>

Current Thread