I'm recursively going through my XML file to create a table of contents
for a document. I want to be able to link each item on the TOC to the
proper anchor later on the page.
So, I end up with something like this:
1. link 1
2. link 2
2.1 link 2.1
2.2 link 2.2
3. link 3
Link1 TITLE + CONTENT...
Link2 TITLE + CONTENT...
link 2.1 TITLE + CONTENT...
link 2.2 TITLE + CONTENT...
Link2 TITLE + CONTENT...
So, for each node, I need to generate a unique anchor to link to.
I could grab the number element and/or title element, but there's no
guarantee that they are all individually unique, so I'd rather rely on
just numbering them myself in the transformation.
From what I can tell, I should use XSL:COUNT for this. This is what I
have now:
<div id="rulesListTOC">
<ul>
<xsl:for-each select="ruleItems/ruleItem">
<xsl:call-template name="rulelistTOC" />
</xsl:for-each>
</ul>
</div>
<xsl:template name="rulelistTOC">
<xsl:for-each select="ruleItem">
<li><a href="#{position()}"><xsl:value-of
select="number" />: <xsl:value-of select="title" /></a>
<xsl:if test="ruleItem">
<ul>
<xsl:call-template
name="rulelistTOC" />
</ul>
</xsl:if>
</li>
</xsl:for-each>
</xsl:template>
The problem is that the 'position()' is reset during each loop of the
recursion. So my links end up as:
1
1
2
2
3
Is there a way around that? Or, perhaps to ask the question more
generally, what method would people recommend for creating a unique
number for each node of the recursive loop?
The 'easy' solution would be for me to just store the unique ID stored
in the database for each node within the XML itself, but I was wondering
if there was a solution on the XSL side of things before I recreate the
XML files.
-Darrel
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--