473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
Jul 20 '05 #1
5 2144
Gerald Aichholzer <ga**@sbox.tugraz.at> writes:
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:template match="@value[.='MyAppletImage']">
<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
Jul 20 '05 #2
Hello David,

David Carlisle wrote:
Gerald Aichholzer <ga**@sbox.tugraz.at> writes:
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


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


This solution works perfectly :)
<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.


$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
Jul 20 '05 #3
<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

Jul 20 '05 #4
<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
Jul 20 '05 #5
Hello David,

David Carlisle wrote:
<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
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
6
by: Rainer Herbst | last post by:
Hi *, please consider the following problem: I have a XML document which includes some html elements. I want to replace only the <div> element: I specified two templates, one matches...
2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
4
by: Adrian Charteris | last post by:
Hi I'm currently trying to use a lookup table for converting one xml doc to another using a XSLT transformation. Ideally I would like my first xml doc to be converted to my second xml doc below. ...
1
by: arnold | last post by:
Hi, I've been knocking my head against the wall trying to create an XSL transform to perform "normalizations" of a set of XML files that have a common structure. % XML file before transform
6
by: John Bailo | last post by:
Given this XML: <?xml version="1.0" encoding="UTF-8"?> <pallet> <position row="0" bay="0" level="A"> <client id="ABC"></client> </position> <position row="1" bay="1" level="B"> <client...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
1
by: boetke | last post by:
Hi all, I am attempting to create an xslt transformation which I am having trouble with. I am fairly new to xslt and am having a hard time getting my head around it. The original xml file looks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.