XSLT: how to match attribute having a specific value?

G

Gerald Aichholzer

Hello NG,

I have an XHMTL-file and would like to replace attribute
values using XSLT. The XHTML-file contains the following
code:

<applet code="MyApplet/MyApplet.class"
archive="prog/MyApplet.jar"
width="100%"
height="99%">
<param name="image" value="MyAppletImage"/>
<param name="select" value="MyAppletSelect"/>
</applet>

I would like to replace MyAppletImage resp. MyAppletSelect
with the correspondg values.

I thought about using the identity transformation plus
a construct like the following (which does not work,
unfortunately):

<xsl:template match="@value='MyAppletImage'">
<xsl:attribute name="value">
<xsl:value-of select="$image"/>
</xsl:attribute>
</xsl:template>

The purpose is to replace only these two attributes and
otherwise leave the original file as it is.

Any help is appreciated.

Thanx in advance,
Gerald
 
D

David Carlisle

Gerald Aichholzer said:
Hello NG,

I have an XHMTL-file and would like to replace attribute
values using XSLT. The XHTML-file contains the following
code:

<applet code="MyApplet/MyApplet.class"
archive="prog/MyApplet.jar"
width="100%"
height="99%">
<param name="image" value="MyAppletImage"/>
<param name="select" value="MyAppletSelect"/>
</applet>

I would like to replace MyAppletImage resp. MyAppletSelect
with the correspondg values.

I thought about using the identity transformation plus
a construct like the following (which does not work,
unfortunately):

<xsl:template match="@value='MyAppletImage'">

match patterns have to have the syntax of an XPath expression that
selects a node set. That is a boolean valued expression. You want
<xsl:attribute name="value">
<xsl:value-of select="$image"/>
$image doesn't appear to be defined here so this must be a global
parameter or variable. That's OK so long as you are replacing all such
attributes by the same image value.

</xsl:attribute>
</xsl:template>

The purpose is to replace only these two attributes and
otherwise leave the original file as it is.

Any help is appreciated.

Thanx in advance,
Gerald

David
 
G

Gerald Aichholzer

Hello David,

David said:
match patterns have to have the syntax of an XPath expression that
selects a node set. That is a boolean valued expression. You want

thank you for pointing this out - I should have known that.
<xsl:template match="@value[.='MyAppletImage']">

This solution works perfectly :)
$image doesn't appear to be defined here so this must be a global
parameter or variable. That's OK so long as you are replacing all such
attributes by the same image value.

$image is a global variable (xsl:param). Ideally I would touch
only value-attributes of param-elements. How could I achieve
this?

<xsl:template match="@value[.='MyAppletImage' and ??='param'>


Thanx for your help,
Gerald
 
D

David Carlisle

<xsl:template match="@value[.='MyAppletImage' and ??='param'>

if your source is xml with html element noames in no-namespace

<xsl:template match="@value[.='MyAppletImage' and parent::param]>

or if it is xhtml


<xsl:template match="@value[.='MyAppletImage' and parent::h:param]>

where h is bound by
xmlns:h="http://www.w3.org/1999/xhtml"
either on this element or on the xsl:stylesheet element.

David
 
D

David Carlisle

<xsl:template match="@value[.='MyAppletImage' and parent::param]">
<xsl:template match="@value[.='MyAppletImage' and parent::h:param]">

or perhaps more naturally (and probably handled more efficiently by your
processor)

<xsl:template match="param/@value[.='MyAppletImage']">
<xsl:template match="h:param/@value[.='MyAppletImage']">

David
 
G

Gerald Aichholzer

Hello David,

David said:
<xsl:template match="@value[.='MyAppletImage' and parent::param]">
<xsl:template match="@value[.='MyAppletImage' and parent::h:param]">

or perhaps more naturally (and probably handled more efficiently by your
processor)

<xsl:template match="param/@value[.='MyAppletImage']">
<xsl:template match="h:param/@value[.='MyAppletImage']">

thank you for your help - works flawlessly :)

Gerald
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top