我想编写一个xslt来转换以下XML:
<instruments>
<instrument>1111-A01</instrument>
<instrument>1111-A02</instrument>
<instrument>2222-A03</instrument>
<instrument>2222-A04</instrument>
</instruments>
转换为以下XML:
<references>
<reference>
<id_celex>1111</id_celex>
<article>A01</article>
<article>A02</article>
</reference>
<reference>
<id_celex>2222</id_celex>
<article>A03</article>
<article>A04</article>
</reference>
</references>
所以我需要在'-'处拆分每个仪器以获得id_celex和article。然后,对于每个唯一的id_celex,我需要创建一个引用与id_celex及其文章 s。
我昨天开始使用xslt,我已经卡住了:p
提前感谢!
我有几行,但因为它不工作,我不确定它是否有用显示它…
看一下:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="instruments">
<references>
<xsl:for-each-group select="instrument" group-by="substring-before(text(),'-')">
<reference>
<id_celex>
<xsl:value-of select="current-grouping-key()"/>
</id_celex>
<xsl:for-each select="current-group()">
<article>
<xsl:value-of select="substring-after(text(),'-')"/>
</article>
</xsl:for-each>
</reference>
</xsl:for-each-group>
</references>
</xsl:template>
</xsl:stylesheet>