xslt code to match and change a value

Discussion in 'XML' started by paul_0403@yahoo.com, Apr 24, 2008.

  1. Guest

    I am looking to find a line in my XML and than change it's value
    through the use of .xslt using match, copy, value-of select, ... code.

    Here is the contents of my XML file

    <l_entries>
    <l_entry>
    <v name="ZZZ" path="{VAR}/tmp"/>
    </l_entry>
    <l_entry>
    <v name="ABC" path="${XYZ}/var"/>
    </l_entry>
    <l_entry>
    <v name="ABC" path="${XYZ}/var1"/>
    </l_entry>
    </l_entries>

    What I want is code to find this line ONLY <v name="ABC" path="${XYZ}/
    var"/>
    Note: its "var" and not "var1", ... and than change
    path="${XYZ}/var to the contents of what ever is stored in my variable
    $XXX (ie c:/tmp/123/abc)

    When the transformation is over my output should look like this

    <l_entries>
    <l_entry>
    <v name="ZZZ" path="{VAR}/tmp"/>
    </l_entry>
    <l_entry>
    <v name="ABC" path="c:/tmp/123/abc"/>
    </l_entry>
    <l_entry>
    <v name="ABC" path="${XYZ}/var1"/>
    </l_entry>
    </l_entries>


    Any help would be greatly appreciated. Thanks in advance to all who
    answer
     
    , Apr 24, 2008
    #1
    1. Advertising

  2. wrote:
    > I am looking to find a line in my XML and than change it's value
    > through the use of .xslt using match, copy, value-of select, ... code.
    >
    > Here is the contents of my XML file
    >
    > <l_entries>
    > <l_entry>
    > <v name="ZZZ" path="{VAR}/tmp"/>
    > </l_entry>
    > <l_entry>
    > <v name="ABC" path="${XYZ}/var"/>
    > </l_entry>
    > <l_entry>
    > <v name="ABC" path="${XYZ}/var1"/>
    > </l_entry>
    > </l_entries>
    >
    > What I want is code to find this line ONLY <v name="ABC" path="${XYZ}/
    > var"/>
    > Note: its "var" and not "var1", ... and than change
    > path="${XYZ}/var to the contents of what ever is stored in my variable
    > $XXX (ie c:/tmp/123/abc)


    You can start with the identity transformation template and add a
    template for that particular attribute e.g.

    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:param name="XXX" select="'c:/tmp/123/abc'"/>

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

    <xsl:template match="v/@path[. = '${XYZ}/var']">
    <xsl:attribute name="path">
    <xsl:value-of select="$XXX"/>
    </xsl:attribute>
    </xsl:template>

    </xsl:stylesheet>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Apr 24, 2008
    #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. hiwa
    Replies:
    0
    Views:
    653
  2. Victor
    Replies:
    2
    Views:
    665
    Victor
    May 17, 2004
  3. Gerald Aichholzer
    Replies:
    5
    Views:
    43,712
    Gerald Aichholzer
    May 25, 2005
  4. ekzept
    Replies:
    0
    Views:
    393
    ekzept
    Aug 10, 2007
  5. John Gordon
    Replies:
    13
    Views:
    513
    Ian Kelly
    Dec 20, 2011
Loading...

Share This Page