V
Victor Engmark
When looking for a method to fetch unique elements and counting the
number of occurences of each of them, I found quite a lot of gross
examples of complex XSL. But after realizing the subtle difference
between "." and "current()", I found a neat way of doing the same
without keys or generate-id():
<xsl:template match="/">
<!-- Selects all "new" elements -->
<xsl:for-each select="//Name[not(.=preceding::Name)]">
<!-- Display the element -->
<xsl:value-of select="."/>
<!-- Count the number of occurences of the element -->
<xsl:value-of select="count(//Name[.=current()])"/>
</xsl:for-each>
</xsl:template>
The clue to why the last "value-of" works is that "." refers dynamically
to each of the "Name" elements in the file, while "current()" refers to
the "Name" element in the sorrounding "for-each" element.
If YOU have found a "neat" way of doing something with XSL, it would be
great if you could post it here as well, preferably as a separate thread
with something like "Tip:" in the beginning of the subject.
number of occurences of each of them, I found quite a lot of gross
examples of complex XSL. But after realizing the subtle difference
between "." and "current()", I found a neat way of doing the same
without keys or generate-id():
<xsl:template match="/">
<!-- Selects all "new" elements -->
<xsl:for-each select="//Name[not(.=preceding::Name)]">
<!-- Display the element -->
<xsl:value-of select="."/>
<!-- Count the number of occurences of the element -->
<xsl:value-of select="count(//Name[.=current()])"/>
</xsl:for-each>
</xsl:template>
The clue to why the last "value-of" works is that "." refers dynamically
to each of the "Name" elements in the file, while "current()" refers to
the "Name" element in the sorrounding "for-each" element.
If YOU have found a "neat" way of doing something with XSL, it would be
great if you could post it here as well, preferably as a separate thread
with something like "Tip:" in the beginning of the subject.