使用xslt更改某些元素的值

时间:2013-07-12 14:16:16

标签: xslt xslt-1.0

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>

在我的xsl中,我正在执行以下操作:

<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>

我打算将其余的productData元素和属性保持不变,但要修改其中的一些元素和属性。但是生成的xml为description元素提供了新值,但只为其余元素提供了text nodes。如何获取productData的所有其余节点?

1 个答案:

答案 0 :(得分:1)

您需要一个可以复制输入内容的标识模板。尝试将此添加到您的XSLT:

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