我的元素有两个数字,例如[ - ],例如120-125。现在使用XSLT,我想获得这两个数字并使用这些值创建XML元素,最后我想要这样的东西:
<first>120</first>
<second>125</second>
我该如何实现?
编辑
我要更改的XML结构看起来像这样:
<issue>
<number>3</number>
<year>2017</year>
<article>
<title>Title</title>
<author>
<firstname>name</firstname>
</author>
<pages>71-72</pages>
<reference>reference</reference>
</article>
</issue>
XSLT:
<issue>
<number>
<xsl:value-of select="number"/>
</number>
<year>
<xsl:value-of select="year"/>
</year>
<xsl:for-each select="article">
<article>
<title>
<xsl:value-of select="title"/>
</title>
<author>
<firstname>
<xsl:value-of select="firstname"/>
</firstname>
</author>
<xsl:template match="pages">
<xsl:copy>
<first>
<xsl:value-of select="substring-before(., '-')" />
</first>
<second>
<xsl:value-of select="substring-after(., '-')" />
</second>
</xsl:copy>
</xsl:template>
<reference>
<xsl:value-of select="reference"/>
</reference>
</article>
</issue>
我想拥有的输出XML:
<issue>
<number>3</number>
<year>2017</year>
<article>
<title>Title</title>
<author>
<firstname>name</firstname>
</author>
<first>71</first>
<second>71</second>
<reference>reference</reference>
</article>
</issue>
您在<xsl:for-each>
内部不能具有<xsl:template match="pages">
。考虑到您共享的XSL,您需要如下修改它。我刚刚修改了用于拆分<pages>
值的代码。您的其余代码保持不变。
<xsl:for-each select="article">
<article>
...
<first><xsl:value-of select="substring-before(pages, '-')" /></first>
<second><xsl:value-of select="substring-after(pages, '-')" /></second>
...
</article>
</xsl:for-each>