This is my Source-XML. It is originally a Word-ML which have been reduced to an own structure. Elements with name "aaa" can have any kind of name. The problem is the handling of footnotes:
<root>
<doc>
<comment>text text text <footnote id="1" > text text text</comment>
<aaa>text text text</aaa>
<aaa>text text text<footnote id="2" /> text text text </aaa>
<aaa>text text text<aaa/> text <footnote id="3" symbol="*"/></aaa>
<aaa>text text text text</aaa>
<aaa>text text text text<aaa>text text text<footnote id="4" /></aaa></aaa>
<aaa>text text text text<aaa>text text text<footnote id="4" /></aaa></aaa>
<aaa>text text text text<aaa>text text text<footnote id="5" /></aaa></aaa>
<aaa>text text text</aaa>
</doc>
</root>
I have to transform this Source-XML in another XML. One thing i have to do is to replace the footnotes with the correspondig Number.
But it is not possible to only use the ID-Attribute. The ID is only an internal number. The footnotes should be progressive an there are following conditions:
- Condition 1: "footnotes" that are a child of node "comment" should be ignored. the whole node "comment" is ignored.
- Condition 2: "footnotes" that have a symbol-attribute do not count (i have to show the symbol and not the number)
- Condition 3: it is possible that some notes have the same id (only a low percentage, but sometimes there are more links to the same footnote).
The Output should look like this (structure is not the same, only the handling of the footnotes is for interest now):
<root>
<doc>
<aaa>text text text</aaa>
<aaa>text text text[1] text text text </aaa>
<aaa>text text text<aaa/> text [*]</aaa>
<aaa>text text text text</aaa>
<aaa>text text text text<aaa>text text text[2]</aaa></aaa>
<aaa>text text text text<aaa>text text text[2]</aaa></aaa>
<aaa>text text text text<aaa>text text text[3]</aaa></aaa>
<aaa>text text text</aaa>
</doc>
</root>
My first thought was to have a global counter-variable which i increment according to the conditions. But since variables in XSLT are immutable it is not really an option.
I also tried to count the previous footnotes which occur before the current footnote.
<xsl:template match="footnote">
<xsl:call-template name="getFootnoteNumber">
<xsl:with-param name="footNodeId" select="@id"/>
</xsl:call-template>
</xsl:template>
<!-- simple template which only counts the footnotes
that occur before the current footnode
the conditions 1, 2 and 3 are not yet included -->
<xsl:template name="getFootnoteNumber">
<xsl:param name="footNodeId"/>
<xsl:value-of select="count(//footnote[position()<=$footNodeId])"></xsl:value-of>
</xsl:template>
<!-- i mostly get value "0",
or other strange numbers: for footNodeID=45 i get value 75,
doesn't really work-->
Is there a possibility to develop a global counter?
Or do i have to go on the other way with counting the previous footnotes? Although i don't really know how to implement condition 3.
Greetings and thx for any answer cpt.oneeye