0

我想编写一个 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_celexarticle。然后,对于每个唯一的id_celex,我需要使用id_celex及其article创建一个引用。

我昨天开始使用 xslt,但我已经卡住了:p

先感谢您!

我有几行,但由于它不起作用,我不确定展示它是否有用......

4

1 回答 1

0

看一看:

<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>
于 2013-05-07T13:10:47.050 回答