xml - XSLT Parent content split between child nodes -


xml:

<text> day light saving starts on  <date>29 march 2015 </date>  in countries      <footnote> <text> according wikipedia </text> </footnote>  in europe </text> 

expected output:

day light saving starts on 29 march 2015 in countries<sup>1</sup> in europe  <sup>1</sup> according wikipedia 

what xslt?

in xslt, trying use node() capture elements , contents, in vain.

<xsl:template match="text"> <xsl:if test= "./footnote">    <xsl:for-each select="node()">      <xsl:if test= "not(name() = footnote">            <xsl:value-of select="text()" />      </xsl:if>      <xsl:if test= "name() = footnote">        <xsl:apply-templates select="text()" mode="footnote"/>      </xsl:if>     </xsl:for-each> </xsl:if> 

<xsl:template match="text/footnote" mode="footnote"> <xsl:element name="footnote">   <xsl:value-of select="." /> </xsl:element> </xsl:template> 

you can <xsl:number>:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:output method="html" indent="yes"/>   <xsl:strip-space elements="*"/>    <xsl:template match="/">     <div>       <div>         <xsl:apply-templates />       </div>       <xsl:apply-templates select="//footnote" mode="footnotes" />     </div>   </xsl:template>    <xsl:template match="footnote" name="index">     <sup>       <xsl:number level="multiple" />     </sup>   </xsl:template>    <xsl:template match="footnote" mode="footnotes">     <div>       <xsl:call-template name="index" />       <xsl:text> </xsl:text>       <xsl:apply-templates select=".//text()" />     </div>   </xsl:template>  </xsl:stylesheet> 

when run on input:

<text>   day light saving starts on   <date>29 march 2015 </date>     <footnote>     <text> marvelous date </text>   </footnote>    in countries   <footnote>     <text> according wikipedia </text>   </footnote>   in europe </text> 

the result is:

<div>   <div>   day light saving starts on   29 march 2015 <sup>1</sup>    in countries   <sup>2</sup>   in europe </div>   <div><sup>1</sup>  marvelous date </div>   <div><sup>2</sup>  according wikipedia </div> </div> 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -