Reputation: 13
Using Muenchian grouping in XSLT 1.0. When used in apply-templates it works for the first <level>
element then fails to output for further <level>
elements.
Sample input XML: note that the siblings of <areas>
can be variable
<levels>
<level>
<areas>
<p1>A</p1>
<p1>B</p1>
<p2>C</p2>
</areas>
</level>
<level>
<areas>
<p3>C</p4>
<p3>D</p3>
<p4>E</p4>
</areas>
</level>
</levels>
Sample XSLT:
<xsl:key name="names" match="*/areas/*" use="local-name(.)" />
<xsl:template match="/levels/*">
<xsl:apply-templates select="./areas/*[generate-id(.)=generate-id(key('names', local-name(.)))]" mode="A" />
</xsl:template>
<xsl:template match="*" mode="A">
<xsl:variable name="category" select="local-name(.)" />
<xsl:element name="{$category}">
</xsl:element>
</xsl:template>
Desired output:
<p1>
<p2>
<p3>
<p4>
Output returned:
<p1>
<p2>
Any ideas on why it ignores the second <level>
element?
Thanks.
Upvotes: 1
Views: 84
Reputation: 167516
You could change
<xsl:template match="/levels/*">
<xsl:apply-templates select="./areas/*[generate-id(.)=generate-id(key('names', local-name(.)))]" mode="A" />
</xsl:template>
to
<xsl:template match="/levels">
<xsl:apply-templates select="level/areas/*[generate-id(.)=generate-id(key('names', local-name(.)))]" mode="A" />
</xsl:template>
Upvotes: 1