Following on from my previous question and the given solution XSL numbering at different levels ....
The previous question dealt with inserting \'footnote\' numbers into
If you want to solve that with three different steps then you need to make sure the second step uses the result of the first step as the input and not the original input, that is, you have to make sure you use the variables a bit differently:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
exclude-result-prefixes="xs math map array"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:mode name="add-footnotes" on-no-match="shallow-copy"/>
<xsl:mode name="add-appnotes" on-no-match="shallow-copy"/>
<xsl:variable name="footnotes">
<xsl:apply-templates mode="add-footnotes"/>
</xsl:variable>
<xsl:variable name="appnotes">
<xsl:apply-templates select="$footnotes/node()" mode="add-appnotes"/>
</xsl:variable>
<xsl:template match="seg[@type = 'foo'] | note" mode="add-footnotes">
<xsl:next-match/>
<footnote/>
</xsl:template>
<xsl:template match="note2" mode="add-appnotes">
<xsl:next-match/>
<appnote/>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="$appnotes/node()"/>
</xsl:template>
<xsl:template match="footnote">
<xsl:copy>
<xsl:number level="any" format="1" from="deposition"/>
</xsl:copy>
</xsl:template>
<xsl:template match="appnote">
<xsl:copy>
<xsl:number level="any" format="a" from="deposition"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
http://xsltfiddle.liberty-development.net/948Fn5a/7
I would think however that you don't need three modes respectively three steps, you could simply add your template creating the appnote
s to the first step/mode:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:mode name="add-notes" on-no-match="shallow-copy"/>
<xsl:variable name="notes">
<xsl:apply-templates mode="add-notes"/>
</xsl:variable>
<xsl:template match="seg[@type = 'foo'] | note" mode="add-notes">
<xsl:next-match/>
<footnote/>
</xsl:template>
<xsl:template match="note2" mode="add-notes">
<xsl:next-match/>
<appnote/>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="$notes/node()"/>
</xsl:template>
<xsl:template match="footnote">
<xsl:copy>
<xsl:number level="any" format="1" from="deposition"/>
</xsl:copy>
</xsl:template>
<xsl:template match="appnote">
<xsl:copy>
<xsl:number level="any" format="a" from="deposition"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
http://xsltfiddle.liberty-development.net/948Fn5a/8
As a variation on that approach, as you only want to transform the deposition
elements and only need to number the other elements in that subtree, it might be easier and more efficient to not use global variables with the whole tree transformed but to only transform the deposition
contents:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:mode name="add-notes" on-no-match="shallow-copy"/>
<xsl:template match="deposition">
<xsl:variable name="notes-added">
<xsl:apply-templates mode="add-notes"/>
</xsl:variable>
<xsl:copy>
<xsl:apply-templates select="$notes-added/node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="seg[@type = 'foo'] | note" mode="add-notes">
<xsl:next-match/>
<footnote/>
</xsl:template>
<xsl:template match="note2" mode="add-notes">
<xsl:next-match/>
<appnote/>
</xsl:template>
<xsl:template match="footnote">
<xsl:copy>
<xsl:number level="any" format="1"/>
</xsl:copy>
</xsl:template>
<xsl:template match="appnote">
<xsl:copy>
<xsl:number level="any" format="a"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
http://xsltfiddle.liberty-development.net/948Fn5a/9