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

Discussion in 'XML' started by Tedros.G@googlemail.com, May 8, 2007.

  1. Guest

    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
    , May 8, 2007
    #1
    1. Advertising

  2. Re: Problem updating an attribute that appears in both root nodeand child node!

    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/
    Martin Honnen, May 8, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dana lees
    Replies:
    9
    Views:
    557
    dana lees
    Dec 14, 2005
  2. will
    Replies:
    1
    Views:
    365
    Xavier Franc
    Sep 17, 2003
  3. Bryan Ax
    Replies:
    6
    Views:
    543
    Peter Flynn
    May 17, 2006
  4. Replies:
    1
    Views:
    1,202
    Joe Kesselman
    Nov 1, 2006
  5. Replies:
    0
    Views:
    222
Loading...

Share This Page