我有以下XML,并希望删除所有ELE标签,编号驻留在一些ELE标签的pH值元素的x属性之前:编号属性
<?xml version="1.0" encoding="UTF-8"?>
<tmx version="1.4">
<body>
<tu>
<prop type="x-Context">-2050338055591740051, -2050338055591740051</prop>
<prop type="x-Origin">TM</prop>
<prop type="x-ConfirmationLevel">Translated</prop>
<tuv>
<seg>
<ele>The text </ele>
<ele>
<ph x="0" type="QIAsymphony"/>
</ele>
<ele> goes </ele>
<ele>
<ph x="0" type="470"/>
</ele>
<ele> here </ele>
<ele>
<ph x="0" type="471"/>
</ele>
<ele>.</ele>
</seg>
</tuv>
<tuv>
<seg>
<ele>El texto </ele>
<ele>
<ph x="0" type="QIAsymphony"/>
</ele>
<ele> se mete </ele>
<ele>
<ph x="0" type="471"/>
</ele>
<ele> aquí </ele>
<ele>
<ph x="0" type="470"/>
</ele>
<ele>.</ele>
</seg>
</tuv>
</tu>
</body>
</tmx>
我有以下XSLT的,则执行编号赋予动作,虽然我不知道什么样的变化,使替换丢失ELE标签,一旦这个元素已经从XML删除:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:key name="ph" match="tuv[1]/seg/ele/ph" use="@type" />
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tuv/seg/ele/ph/@x">
<xsl:attribute name="x">
<xsl:value-of select="count(key('ph', ../@type)/../preceding-sibling::ele[ph]) + 1" />
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
所需的输出:
<tuv>
<seg>The text
<ph x="1" type="QIAsymphony"/>
goes
<ph x="3" type="471"/>
here
<ph x="2" type="470"/>
.
</seg>
</tuv>
我不明白的问题 - 当前的XSLT没有删除任何东西,它只是调整'的x'属性' ph'元素。如果您可以编辑问题并添加一个您希望产生的输出样本,则可能会更清楚,因此我们可以更清楚地看到需要更改的内容。 – 2014-09-03 13:43:40
我会改变。我希望能够对上述XML执行此编号操作,但毕竟标签已被删除。我想知道我需要对上述XSLT进行哪些更改才能实现此目的。 –
user3289842
2014-09-03 14:19:00
以下是(部分)所需输出: El texto se mete aquí 。 \t \t \t \t \t \t \t –
user3289842
2014-09-03 14:22:30