I have the following XML:
<InterSection criteria="Microsoft-ASP">value</Intersection>
<InterSection criteria="Microsoft-MVC">value</Intersection>
<InterSection criteria="HP-MVC">value</Intersection>
I need to create TOC at top of my HTML page and so I need to group by criteria (First part before ‘-‘).
I need distinct values like
- Microsoft
- HP
My XSLT have following code
<a>
<xsl:attribute name="href">
<xsl:text>#trigger</xsl:text>
<xsl:value-of select="position()"/>
</xsl:attribute>
<xsl:for-each-group select="." group-by="substring-before(@Criteria, ' - ')">
<xsl:value-of select="substring-before(@Criteria, ' - ')"/>
<xsl:text>
</xsl:text>
</xsl:for-each-group>
</a>
But somehow i am getting
- Microsoft
- Microsoft
- HP
instead of
1. Microsoft
2. HP
I have following written in my XSLT
<xsl:template match="InterSection" mode="TOC">
<li>
<a>
<xsl:attribute name="href">
<xsl:text>#trigger</xsl:text>
<xsl:value-of select="position()"/>
</xsl:attribute>
<xsl:for-each-group select="." group-by="substring-before(@Criteria, ' - ')">
<xsl:value-of select="current-grouping-key()"/>
<xsl:for-each select="current-group()"/>
</xsl:for-each-group>
</a>
</li>
I’m finally going to summarize the problems I would fix in your work in order to make it work (deleted previous edits):
criteriausing the wrong casesubstringexpression contains too much spaces around the second argument-current-grouping-key()to get the value of the current matching groupInterSection(Root) and then you have to iterate onInterSectionlike you would do withxsl:for-each