天天看点

使用xslt批量修改xml 节点name

Created by Jerry Wang, last modified on Jun 06, 2014

修改之前的xml file:

<xsl:transform
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style"
   version="1.0">
 <xsl:strip-space elements="*"/>
 <xsl:template match="/">
     <xsl:apply-templates/>
</xsl:template>
 <xsl:template match="node()">
   <xsl:choose>
     <xsl:when test="starts-with(name(),'n0:')">
       <xsl:element name="{name()}">
       <xsl:attribute name="elementFormDefault">
          qualified
       </xsl:attribute>
       <xsl:apply-templates select="node()"/>
       </xsl:element>
     </xsl:when>
     <xsl:when test="name()=''">
     <xsl:value-of select="."/>
     <xsl:copy-of select = "@*"/>
     </xsl:when>
     <xsl:otherwise>
       <xsl:element name="{concat('n0:', name())}">
       <xsl:apply-templates select="node()"/>
       </xsl:element>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
</xsl:transform>
      

使用下列transformation:

如果node name已经是以no:开头,则给该节点加上attribute elementFormDefault,其value为"qualified".