使用xslt更改某些元素的值 输入xml结构如下所示: fdad dfsa fdad dfsa fdad dfsa
在我的xsl中,我执行以下操作:使用xslt更改某些元素的值 输入xml结构如下所示: fdad dfsa fdad dfsa fdad dfsa,xslt,xslt-1.0,Xslt,Xslt 1.0,在我的xsl中,我执行以下操作: The input xml structure is like this: <Envelopes> <env:Envelope> <urn:MyFunction> <parameter1 attr1='df'>fdad</parameter1> <parameter2 attr2='ww'>dfsa</parameter2>
The input xml structure is like this:
<Envelopes>
<env:Envelope>
<urn:MyFunction>
<parameter1 attr1='df'>fdad</parameter1>
<parameter2 attr2='ww'>dfsa</parameter2>
<productData>
<Id></Id>
<Description></Description>
<Price><Price>
</productData>
</urn:MyFunction>
</env:Envelope>
<env:Envelope>
<urn:MyFunction1>
<parameter1 attr1='df'>fdad</parameter1>
<parameter2 attr2='ww'>dfsa</parameter2>
<productData>
<Id></Id>
<Description></Description>
<Price><Price>
</productData>
</urn:MyFunction>
</env:Envelope>
<env:Envelope>
<urn:MyFunction1>
<parameter1 attr1='df'>fdad</parameter1>
<parameter2 attr2='ww'>dfsa</parameter2>
<productData>
<Id></Id>
<Description></Description>
<Price><Price>
</productData>
</urn:MyFunction>
</env:Envelope>
<Envelopes>
新描述
我打算保持
productData
元素和属性的其余部分不变,但修改其中一些。但是,生成的xml为description
元素提供了新的值,但对于其余元素,只提供了文本节点
。如何获取productData的所有其余节点?您需要一个可以复制输入内容的标识模板。尝试将其添加到XSLT中:
<xsl:template match="/">
<NewEnvelopes>
<xsl:for-each select="//productData">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</NewEnvelopes>
</xsl:template>
<xsl:template match="productData/Description">
<Description>new Description</Description>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>