[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] XSL ver. 2 to copy, replace, and insert new node
Subject: [xsl] 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 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XML tags as map keys and , Wendell Piez | Thread | [xsl] output modified branch - best, Heiko Niemann |
Re: [xsl] Could not select the text, Jack Bush | Date | Re: [xsl] XML tags as map keys and , Eliot Kimber |
Month |