xml - counting elements and using the count -


i have 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 that? of course, in real source, there can many more <lat:sup/> 's . there may more 1 <p> within <blockquote>, need count lat:sup's within blockquote, ignoring p.

you can use xsl:number.

here's example (removed lat: prefix 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> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -