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

using XSLT i want to replace id=1 with <group appearance = "field-list">

1
  • Note that your XML is not well-formed. I've made the necessary corrections in my answer below. Commented Sep 17, 2014 at 11:47

1 Answer 1

1

Use the identity transform, overriding the part you wish to replace with something different. To wit:

Given this input XML document:

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

This XSLT transformation:

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

Will produce this output XML document:

<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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.