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

T

Tedros.G

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:eek:utput 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top