xslt code to match and change a value

P

paul_0403

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
 
M

Martin Honnen

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>
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top