[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: XSL ver. 2 to copy, replace, and insert new node
From: Henry Dong <henryb.dong@xxxxxxxxx>
Date: Fri, 18 Jun 2010 12:48:39 -0700
 XSL ver. 2 to copy
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.