繁体   English   中英

使用xslt如何替换节点

[英]using xslt how to replace the node

<h:body>
<group id = "1">
<name>xxx</name>
<age>12</age>
<group id = "2">
<name>yyy</name>
<age>13</age>
</h:body>

使用XSLT,我想将id = 1替换为<group appearance = "field-list">

使用标识转换 ,用其他替换您要替换的部分。 以机智:

给定此输入XML文档:

<h:body xmlns:h="http://example.org/h">
  <group id = "1">
    <name>xxx</name>
    <age>12</age>
  </group>
  <group id = "2">
    <name>yyy</name>
    <age>13</age>
  </group>
</h:body>

此XSLT转换:

<xsl:stylesheet version="1.0"
                xmlns:h="http://example.org/h"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>

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

  <xsl:template match="group[@id = '1']">
    <group appearance = "field-list">
      <xsl:apply-templates select="node()|@*"/>
    </group>
  </xsl:template>
</xsl:stylesheet>

将产生此输出XML文档:

<h:body xmlns:h="http://example.org/h">
  <group appearance="field-list" id="1">
      <name>xxx</name>
      <age>12</age>
  </group>
  <group id="2">
      <name>yyy</name>
      <age>13</age>
  </group>
</h:body>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM