xml - Counting only specific element -


edit: sorry question bit unclear, i'm trying return text in p nodes , children while counting individual p nodes. <1> refers first p node, <2> second , on.

i'm trying count occurrence of individual element regardless of appears in structure of xml document. i've tried variations of position() , count() both , without for-each loops , can't seem find work. have idea on how this?

an example document be:

<text>    <body>      <div1>        <p>abc</p>          <div2>            <p>def</p>          </div2>      </div1>      <div1>        <p>ghi</p>          <div2>            <p>jkl <name>adam</name></p>            <div3>               <p>mno</p>            </div3>          </div2>      <p>qrs</p>      </div1>  </body> </text> 

with return:

<1>abc <2>def <3>ghi <4>jkl adam <5>mno <6>qrs 

xsl:number friend here. use number

<xsl:number select="p" level="any" /> 

note use of level in instance.

try xslt

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">    <xsl:output method="text" />     <xsl:template match="p">        <xsl:number select="p" level="any" />        <xsl:value-of select="concat(') ', ., '&#10;')" />    </xsl:template>     <xsl:template match="text()"/> </xsl:stylesheet> 

this should output following

1) abc 2) def 3) ghi 4) jkl adam 5) mno 6) qrs 

note use of template matching text() stop text in elements other p being output (should have any).


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -