[英]XSLT Parent content split between child nodes
XML: XML:
<text> Day light saving normally starts on
<date>29 March 2015 </date>
in some countries
<footnote> <text> According to wikipedia </text> </footnote>
in Europe </text>
Expected Output: 预期产量:
Day light saving normally starts on 29 March 2015 in some
countries<sup>1</sup> in Europe
<sup>1</sup> According to wikipedia
What could be the XSLT? XSLT可能是什么?
In my XSLT, I am trying to use node() to capture all the elements and contents, but in vain. 在我的XSLT中,我试图使用node()捕获所有元素和内容,但是徒劳无功。
<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 do this with <xsl:number>
: 您可以使用
<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 this input: 在此输入上运行时:
<text>
Day light saving normally starts on
<date>29 March 2015 </date>
<footnote>
<text> A very marvelous date </text>
</footnote>
in some countries
<footnote>
<text> According to wikipedia </text>
</footnote>
in Europe
</text>
The result is: 结果是:
<div>
<div>
Day light saving normally starts on
29 March 2015 <sup>1</sup>
in some countries
<sup>2</sup>
in Europe
</div>
<div><sup>1</sup> A very marvelous date </div>
<div><sup>2</sup> According to wikipedia </div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.