Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT

Reply
 
 
srini
Guest
Posts: n/a
 
      04-05-2004
Hello everyone,
I'm trying to transform this xml to another xml but couldn't
quite figure it out.
Source.xml

<all>
<object name="objname" value="objvalue">
<elem1 att="value" att2="value"/>
<elem1 att="value" att2="value"/>
<object name="name" value="645">
<items>
<item itemno="1a" itemname="name"/>
<item itemno="1b" itemname="name"/>
<item itemno="1c" itemname="name"/>
</items>
</object>
<object name="name" value="646">
<items>
<item itemno="2a" itemname="name"/>
<item itemno="2b" itemname="name"/>
<item itemno="2c" itemname="name"/>
</items>
</object>
</object>
</all>

I want to transform the above document to another xml which looks
exactly the same except the itemno with value 2b would have a
different value say 3b. The <object> element under <all> can have any
number of elements.
here's the output
<all>
<object name="objname" value="objvalue">
<elem1 att="value" att2="value"/>
<elem1 att="value" att2="value"/>
<object name="name" value="645">
<items>
<item itemno="1a" itemname="name"/>
<item itemno="1b" itemname="name"/>
<item itemno="1c" itemname="name"/>
</items>
</object>
<object name="name" value="646">
<items>
<item itemno="2a" itemname="name"/>
<item itemno="3b" itemname="name"/>
<item itemno="2c" itemname="name"/>
</items>
</object>
</object>
</all>

I'd appreciate any help from anyone.

Thanks,
Srini
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-06-2004


srini wrote:

> Hello everyone,
> I'm trying to transform this xml to another xml but couldn't
> quite figure it out.
> Source.xml
>
> <all>
> <object name="objname" value="objvalue">
> <elem1 att="value" att2="value"/>
> <elem1 att="value" att2="value"/>
> <object name="name" value="645">
> <items>
> <item itemno="1a" itemname="name"/>
> <item itemno="1b" itemname="name"/>
> <item itemno="1c" itemname="name"/>
> </items>
> </object>
> <object name="name" value="646">
> <items>
> <item itemno="2a" itemname="name"/>
> <item itemno="2b" itemname="name"/>
> <item itemno="2c" itemname="name"/>
> </items>
> </object>
> </object>
> </all>
>
> I want to transform the above document to another xml which looks
> exactly the same except the itemno with value 2b would have a
> different value say 3b. The <object> element under <all> can have any
> number of elements.
> here's the output
> <all>
> <object name="objname" value="objvalue">
> <elem1 att="value" att2="value"/>
> <elem1 att="value" att2="value"/>
> <object name="name" value="645">
> <items>
> <item itemno="1a" itemname="name"/>
> <item itemno="1b" itemname="name"/>
> <item itemno="1c" itemname="name"/>
> </items>
> </object>
> <object name="name" value="646">
> <items>
> <item itemno="2a" itemname="name"/>
> <item itemno="3b" itemname="name"/>
> <item itemno="2c" itemname="name"/>
> </items>
> </object>
> </object>
> </all>
>
> I'd appreciate any help from anyone.


Use identity transformation for everying but <item itemno="2b" ... />:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xslutput method="xml" encoding="UTF-8" />

<xsl:template match="item[@itemno = '2b']">
<xsl:copy>
<xsl:attribute name="itemno">3b</xsl:attribute>
<xsl:apply-templates select="@*[local-name() != 'itemno']" />
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>

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

</xsl:stylesheet>

--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
 
srini ganesan
Guest
Posts: n/a
 
      04-11-2004


Thanks a lot for your solution Martin. It worked and I appreciate your
help.

Srini

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Including XSLT/XML document within a XSLT document dar_imiro@hotmail.com XML 4 12-13-2005 02:26 AM
Multiple XSLT Transforms using a Controller XSLT sneill@mxlogic.com XML 2 10-19-2005 11:00 AM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
xslt alone or xslt/java for static site? ted XML 1 01-26-2004 10:41 AM
[XSLT]Passing values from Javascript to a XSLT variable Benjamin Hillsley XML 3 09-25-2003 04:50 AM



Advertisments