0

我认为这很棘手。我想要下面的 xml,将 getpositionrouter 元素更改为“newelement”。问题是,这应该是输入输出的唯一变化。即使是命名空间“pos”,也应该保留。所以在输入而不是 pos 中它可以是 ns1="positionNS"。然后输出也ns1,应该在那里。

input


<pos:getPositionRouter xmlns:pos="positionNS">
   <positionID>
      <code>1</code>
   </positionID>
   <parameter>?</parameter>
</pos:getPositionRouter>

期望的输出

<pos:newelement xmlns:pos="positionNS">
   <positionID>
      <code>1</code>
   </positionID>
   <parameter>?</parameter>
</pos:newelement>
4

1 回答 1

0

尝试遵循样式表

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pos="positionNS">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="/">
        <xsl:apply-templates select="pos:getPositionRouter" />
    </xsl:template>

    <xsl:template match="pos:getPositionRouter">
        <pos:newElement>
            <xsl:apply-templates select="node() |  @*" />
        </pos:newElement>
    </xsl:template>

    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() |  @*" />
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>
于 2013-07-06T20:13:00.393 回答