Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xslt code to match and change a value

Reply
Thread Tools

xslt code to match and change a value

 
 
paul_0403@yahoo.com
Guest
Posts: n/a
 
      04-24-2008
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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-24-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xslaram 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/
 
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
text box value does not match value on postback allan.palmer@cit.com ASP .Net 2 12-21-2007 07:03 PM
pat-match.lisp or extend-match.lisp in Python? ekzept Python 0 08-10-2007 06:08 PM
XSLT: how to match attribute having a specific value? Gerald Aichholzer XML 5 05-25-2005 10:55 AM
$match = true() for empty $match?? Victor XML 2 05-17-2004 10:43 AM
Java regex can't match lengthy match? hiwa Java 0 01-29-2004 10:09 AM



Advertisments