
July 20th, 2005, 09:40 AM
| | | XSLT: how to match attribute having a specific value?
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 | 
July 20th, 2005, 09:40 AM
| | | Re: XSLT: how to match attribute having a specific value?
Gerald Aichholzer <gary@sbox.tugraz.at> writes:
[color=blue]
> 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'">[/color]
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:template match="@value[.='MyAppletImage']">
[color=blue]
> <xsl:attribute name="value">
> <xsl:value-of select="$image"/>[/color]
$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.
[color=blue]
> </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[/color]
David | 
July 20th, 2005, 09:40 AM
| | | Re: XSLT: how to match attribute having a specific value?
Hello David,
David Carlisle wrote:[color=blue]
> Gerald Aichholzer <gary@sbox.tugraz.at> writes:
>[color=green]
>>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'">[/color]
>
>
> match patterns have to have the syntax of an XPath expression that
> selects a node set. That is a boolean valued expression. You want[/color]
thank you for pointing this out - I should have known that.
[color=blue]
> <xsl:template match="@value[.='MyAppletImage']">[/color]
This solution works perfectly :)
[color=blue][color=green]
>> <xsl:attribute name="value">
>> <xsl:value-of select="$image"/>[/color]
>
> $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.[/color]
$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 | 
July 20th, 2005, 09:40 AM
| | | Re: XSLT: how to match attribute having a specific value?
<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 | 
July 20th, 2005, 09:40 AM
| | | Re: XSLT: how to match attribute having a specific value?
<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 | 
July 20th, 2005, 09:40 AM
| | | Re: XSLT: how to match attribute having a specific value?
Hello David,
David Carlisle wrote:[color=blue]
> <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']">
>[/color]
thank you for your help - works flawlessly :-)
Gerald |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|