473,394 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XSLT

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
Jul 20 '05 #1
2 2398


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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output 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/

Jul 20 '05 #2


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!
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ted | last post by:
Was wondering if XSLT alone is appropriate for the following situation. From XML, I'm creating a small website (around 50 pages) with pages that link to each other through a nav menu and a...
2
by: Tom Corcoran | last post by:
I am working to ease updating of a html page by transforming 2 xml files. I was going to use xslt for this and had bought 2 unopened books, wrox xslt and o'reilly's xslt cookbook. But am now...
1
by: Mohit | last post by:
Hi Friends I have to call 1 of the 2 child XSLT files from the Main XSLT file based on some criteria. I want one child XSLT file will be executed by version 1 of XSLT processor and the other by...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
3
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
3
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION>...
1
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.