Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Problem updating an attribute that appears in both root node and child node!

Reply
Thread Tools

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

 
 
Tedros.G@googlemail.com
Guest
Posts: n/a
 
      05-08-2007
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" xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlnssi="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" xmlnssl="http://www.w3.org/1999/XSL/
Transform">
<xslutput 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" xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlnssi="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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      05-08-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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/
 
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
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
select nodes with child node A and child node B gplott@yahoo.com XML 1 11-01-2006 09:27 PM
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
problem with child text node when constraining other child node types Bryan Ax XML 6 05-17-2006 09:08 PM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM



Advertisments