使用xsl恢复值

时间:2014-05-13 13:46:11

标签: xml xslt

我需要使用xsl处理双语xml文件,但我的循环显然存在问题。目的是在我的样式表上复制我的每个节点的值,即:apple - > pomme(见下面的预期输出)

我的输入文件

    <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="reinsert.xsl"?>

<translate>
  <extract count="1">bonjour</extract>
  <extract count="2">pomme</extract>
</translate>

我的输出文件

<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" version="1.1">
  <file source-language="fr" datatype="plaintext" target-language="en">
    <body>
      <trans-unit approved="yes" id="1">
        <source>hi</source>
        <target>bonjour</target>
      </trans-unit>
      <trans-unit approved="yes" id="2">
        <source>Apple2</source>
        <target>bonjour</target>
      </trans-unit>
      <trans-unit approved="yes" id="1">
        <source>hi</source>
        <target>pomme</target>
      </trans-unit>
      <trans-unit approved="yes" id="2">
        <source>Apple2</source>
        <target>pomme</target>
      </trans-unit>
    </body>
  </file>
</xliff>

预期输出

    <?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" version="1.1">
  <file source-language="fr" datatype="plaintext" target-language="en">
    <body>
      <trans-unit approved="yes" id="1">
        <source>hi</source>
        <target>bonjour</target>
      </trans-unit>
      <trans-unit approved="yes" id="2">
        <source>Apple</source>
        <target>pomme</target>
      </trans-unit>
    </body>
  </file>
</xliff>

我的样式表:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
 <xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" version="1.1">
  <file source-language="fr" datatype="plaintext" target-language="en">
    <body>
    <xsl:for-each select="/translate/extract">
            <trans-unit xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:space="preserve" approved="yes" id="1">

                <source>hi</source>
                <target>
                  <xsl:apply-templates select="." />
                </target>

            </trans-unit>
            <trans-unit xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:space="preserve" approved="yes" id="2">
                <source>Apple</source>
                <target>
                <xsl:apply-templates select="." />
                </target>

            </trans-unit>

  </xsl:for-each>  
    </body>
  </file>
</xliff>  
    </xsl:template>
</xsl:stylesheet>

非常感谢!

0 个答案:

没有答案