欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

使用xslt批量修改xml 节点name

发布时间:2023/12/19 编程问答 51 豆豆
生活随笔 收集整理的这篇文章主要介绍了 使用xslt批量修改xml 节点name 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

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

修改之前的xml file:

使用下列transformation:

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

  • 否则将所有节点的name加上前缀n0:

  • <xsl:transformxmlns: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之后的xml:

    总结

    以上是生活随笔为你收集整理的使用xslt批量修改xml 节点name的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。