Reputation: 954
I have this source:
<blockquote><p> word1<lat:sup/> word2<lat:sup/> word3<lat:sup/> </p></blockquote>
desired output:
<blockquote><p>word1<sup>1</sup> word2<sup>2</sup> word3<sup>3</sup></p></blockquote>
How can I do that?
of course, in the real source, there can be many more <lat:sup/>
's .
There may be more than one <p>
within the <blockquote>
, but I need to count the lat:sup's within the blockquote, ignoring the p.
Upvotes: 1
Views: 36
Reputation: 52848
You can use xsl:number
.
Here's an example (removed the lat:
prefix for simplicity)
XML Input
<blockquote>
<p> word1<sup/> word2<sup/> word3<sup/> </p>
<p> wordA<sup/> wordB<sup/> wordC<sup/> </p>
</blockquote>
XSLT 2.0
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="sup">
<sup>
<xsl:number from="blockquote" level="any"/>
</sup>
</xsl:template>
</xsl:stylesheet>
Output
<blockquote>
<p> word1<sup>1</sup> word2<sup>2</sup> word3<sup>3</sup>
</p>
<p> wordA<sup>4</sup> wordB<sup>5</sup> wordC<sup>6</sup>
</p>
</blockquote>
Upvotes: 2