473,385 Members | 2,004 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,385 software developers and data experts.

Problem updating an attribute that appears in both root node and child node!

Hi
I have an attribute the appears in both the root node and child node
for example, below the attribute VERSION appears in the rood node
(PRODMSG ) and a child node (OPERATION )
================
INPUT XML
================
<?xml version="1.0" encoding="utf-16"?>
<PRODMSG VERSION="1.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
ID="00051004_20070503024353">
<HEADER>
<OPERATION NAME="PRICE" VERSION="1.2">
<USERNAME>SMITGHJ</USERNAME>
<HOSTNAME>00051004</HOSTNAME>
<DATETIME>2007-05-03T01:30:16.710</DATETIME>
</OPERATION>
</HEADER>
</PRODMSG>

However all I want to do is update the root node (PRODMSG) VERSION
attribute to 2.0 but leave the child node version untouched. Problem
is if I select the PRODMSG and it's attributes and update the version
to 2.0

.......
<xsl:template match="@VERSION|PRODMSG">
<xsl:attribute name="VERSION">2.0</xsl:attribute>
</xsl:template>
......

I get nothing but if I do this .......

================
TRANSFORM
================

<?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" version="1.0" encoding="UTF-8" indent="yes"/
>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

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

<!--UPDATE the version number to 2.0 -->
<xsl:template match="@VERSION">
<xsl:attribute name="VERSION">2.0</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
I get the following output (ALL the versions are updated to 2.0) .

================
OUTPUT XML
================
<?xml version="1.0" encoding="utf-16"?>
<PRODMSG VERSION="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
ID="00051004_20070503024353">
<HEADER>
<OPERATION NAME="PRICE" VERSION="2.0">
<USERNAME>SMITGHJ</USERNAME>
<HOSTNAME>00051004</HOSTNAME>
<DATETIME>2007-05-03T01:30:16.710</DATETIME>
</OPERATION>
</HEADER>
</PRODMSG>

Please can you tell me what I am doing wrong....

Thank you
Ted

May 8 '07 #1
1 1930
Te******@googlemail.com wrote:
<!--UPDATE the version number to 2.0 -->
<xsl:template match="@VERSION">
Change the match attribute to
<xsl:template match="PRODMSG/@VERSION">
<xsl:attribute name="VERSION">2.0</xsl:attribute>
</xsl:template>
</xsl:stylesheet>


--

Martin Honnen
http://JavaScript.FAQTs.com/
May 8 '07 #2

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

Similar topics

2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
14
by: Lee Franke | last post by:
I can't seem to figure this one out. Here is my class structure namespace name { public class foo { } }
9
by: Rocky | last post by:
I have 2 textboxes. When I click submit, i want to add whatevers in the text box1 as username and whatevers in textbox2 as userid into an xml file. How do I do that in ASP.NET using vb.net? My...
2
by: Nicholas Sherlock | last post by:
Hey all, I wrote a class to represent a node in a site navigation tree which contains methods for building the tree from the database. I also wrote some routines to print out the whole tree,...
7
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a...
2
by: WhiteWizard | last post by:
This should be easy, and it probably is, I just can't find anything on it. I have to build an XML Document object in memory, add some child nodes, save it, and then if another condition arises,...
5
by: patrin | last post by:
Hi All, given the source document: <?xml version="1.0" encoding="UTF-8"?> <root> <child> <test id="1" name="first child"/> </child> <child>
0
by: Alex Brown | last post by:
Is it a problem to attach Non-static site map providers under one that inherits from StaticSiteMapProvider ? We are implementing a custom site map provider for a website that is being converted...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.