xsl-list
[Top] [All Lists]

[xsl] XSL ver. 2 to copy, replace, and insert new node

2010-06-18 14:49:04
Hi,
  I'm not sure how to complete my XSL using XSL 2.0 to copy, replace,
and insert a new node.  Your help will be greatly appreciated.  Thank
you.

 I have a xml that look like below

 <root>
      <one> test1 </one>
      <two> test2 </two>
      <group>
          <aaa> test3 </aaa>
          <bbb>
              <data>test4 </data>
          </bbb>
          <ccc>test5</ccc>
      </group>
 </root>

I want to copy my XML to a new XML with a few changes.
     If <one> or <aaa> is there, I want to replace it with a new value
     If <bbb> is there, I want to replace the sub node <data> value
with a new value
     If <bbb> or <ddd> is NOT there, I want to insert <bbb> between
<aaa> and <ccc>, and add a new node <ddd> below the <ccc> based on my schema

Here is my incompleted or incorrect XSL file,
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
    <xsl:template match="@*|node()" />
       <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
       </xsl:copy>
    </xsl:template>
    <xsl:template mach="group">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
            <xsl:choose>
                  <xsl:when test="not(b)">
                           ...............
                  </xsl:when>
                  <xsl:when test="b">
                             ...........
                  </xsl:when>
                  <xsl:when test ="not(d)">
                       <xsl:element name="d"> test6</xsl:element>
                  </xsl:when>
                  <xsl:when test="d">
                         <xsl:text>test6 </xsl:text>
                  </xsl:when>
             </xsl:choose>
         </xsl:copy>
     </xsl:template>
</xsl:stylesheet>

---------------------------------------------
The result I would like to get is

 <root>
     <one> new value 1 </one>
     <two> test2 </two>
     <group>
          <aaa> new value 2 </aaa>
             <bbb>
                  <data> new value 3 </data>
             </bbb>
             <ccc>test5</ccc>
             <ddd> new value 4 </ddd>
    </group>
  </root>

Henry

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] XSL ver. 2 to copy, replace, and insert new node, Henry Dong <=