The structure of my style sheet is as following:
<xsl:apply-templates select="pattern1|pattern2|pattern3"/>
...
<xsl:template match="pattern1|pattern2|pattern3">
<xsl:variable name="counter">
<xsl:number/>
</xsl:variable>
...
</xsl:template>
The counter variable is reset for each pattern. I want to get a counter for all the matches.
How can I achieve it?
Thanks!
XML source structure as follow:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<div class="entry">
<div class="headword">
...
</div>
<div class="information-forms">
test infomation block
</div>
<div class="definition">
<div>text </div>
<div>text </div>
... ...
<div>text </div>
</div>
<div class="example-sentences">
<ol>
<li>sentence here</li>
<li>sentence here</li>
... ...
<li>sentence here</li>
</ol>
</div>
<div class="synonyms-reference">
<div class="syn-para">
Synonyms: ... ...
</div>
<div class="ant-para">
Antonyms: ... ...
</div>
<div class="...">
...
</div>
</div>
</div>
<div class="entry">
...
</div>
<div class="entry">
...
</div>
... ...
</root>
I want to get a counter of nodes of multiple patterns under each div[@class=”entry”] node.
So the counter should be reset when starting in a new div[@class=”entry”] node.
XPath of the patterns is
div[@class='information-forms']
|
div[@class='definition'].div
|
div[@class='example-sentences']/ol/li
I can figure out how to do it by parse it twice with xsl style sheet.( First time put all matching nodes in one node.) But It seems to me that it can be done in a single pass. I hope someone experienced in XSL/XSLT can help me. Thanks.
Try the following. Explanation: call a specific template for the set of nodes to be processed, supplying the set as a parameter, then use position() within the template.
With the XML input you supplied, this gives as result