I now came to the last step of my XSL stylesheet, which needs me to output a number representing the total number of nodes added. Actually, it doesn't seem to be so straight-forward to me:
First of all, I am not counting the nodes from the original xml document, I am going to count certain nodes from the resulting XML(the initial xml document could be empty).
Secondly, I am not counting all of the nodes.
For example, here is a piece of my XSLT code:
<xsl:template name="Loop2000A">
<Loop2000A>
<HL>
<HL01>
<xsl:value-of select="'1'"/>
</HL01>
<HL03>
<xsl:value-of select="'20'"/>
</HL03>
</HL>
<xsl:if test="$recbat//provider_taxonomy_qual !='' ">
<PRV>
<PRV01>
<xsl:value-of select="'BI'"/>
</PRV01>
<PRV02>
<xsl:value-of select="$recbat//provider_taxonomy_qual"/>
</PRV02>
<PRV03>
<xsl:value-of select="$recbat//provider_taxonomy"/>
</PRV03>
</PRV>
</xsl:if>
<xsl:call-template name="Loop2010AA"/>
So for this code, and are called segments, and those $recbat etc. are data sources. So want I really want to count is the number of these segments, and it can across different templates(like "Loop2010AA" template above, which is another template), and these segments may have loops, so they may be created 3 times consecutively, which our counter should increment 3 accordingly, or maybe the "if" statement fails, thus no such segment gets created, then the counter should stay the same.
I am not sure the right way to implement this, since most of the tutorial I've googled are about counting the nodes in the original XML documents. One idea now I have is to use the parameter passing, but I have no idea then how to make this parameter a global one?
Alternatively, I am thinking of a more direct way of doing this. Instead of using a counter variable, is there any way that I can generate the output xml document first, then I count the nodes I want in this xml and then generate the TRUE output with the number in it.
scan
pattern. Without stylesheet I can only suggest a two phase transformation: output everything into a variable and then count the nodes. – user357812