0

以下是我的 input.xml 文件中的部分代码:

<info>
<name>
<surname>Sachin</surname>
<x> </x>
<given-names>J</given-names>
</name>
<x>, </x>
<name>
<surname>Sushant</surname>
<x> </x>
<given-names>K</given-names>
</name>
</info>

当我使用copy-of元素复制这些节点时

<xsl:copy-of select="info"></xsl:copy-of>

然后生成以下输出:

<info>
<name>
<surname>Sachin</surname>
<x xml:space="preserve"> </x>
<given-names>J</given-names>
</name>
<x xml:space="preserve">, </x>
<name>
<surname>Sushant</surname>
<x xml:space="preserve"> </x>
<given-names>K</given-names>
</name>
</info>

我想xml:space="preserve"从我的 output.xml 文件中删除。

4

1 回答 1

3

xsl:copy-of 进行精确复制。如果您想进行任何更改,无论多么小,那么您需要使用“修改后的身份模板”编码模式。在这种情况下,应该使用以下模板规则:

<xsl:template match="*">
  <xsl:copy>
    <xsl:copy-of select="@* except xml:space"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

(“except”运算符是 XPath 2.0 - 如果您坚持使用 1.0,请使用@*[name() != 'xml:space']

于 2011-07-29T18:55:01.817 回答