473,568 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="MyApplet Image"/>
<param name="select" value="MyApplet Select"/>
</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:attribut e 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 2154
Gerald Aichholzer <ga**@sbox.tugr az.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="MyApplet Image"/>
<param name="select" value="MyApplet Select"/>
</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[.='MyAppletImag e']">
<xsl:attribut e 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.tugr az.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="MyApplet Image"/>
<param name="select" value="MyApplet Select"/>
</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[.='MyAppletImag e']">


This solution works perfectly :)
<xsl:attribut e 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[.='MyAppletImag e' and ??='param'>
Thanx for your help,
Gerald
Jul 20 '05 #3
<xsl:template match="@value[.='MyAppletImag e' and ??='param'>

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

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

or if it is xhtml
<xsl:template match="@value[.='MyAppletImag e' 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[.='MyAppletImag e' and parent::param]">
<xsl:template match="@value[.='MyAppletImag e' and parent::h:param]">

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

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

David
Jul 20 '05 #5
Hello David,

David Carlisle wrote:
<xsl:template match="@value[.='MyAppletImag e' and parent::param]">
<xsl:template match="@value[.='MyAppletImag e' and parent::h:param]">

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

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


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
2687
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 extension responsible for the xslt functions. The problem i have is that the obtained transformation is not the waited one. I try to proccess the...
6
4422
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 everything ("*"), one matches only the "div". As far as I understand, the most specific rule should apply, i.e. the div rule if the element is a <div>.
2
3391
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 happening when I put my XML files and the .xsl files on my ISP's system for my home page. If I try to open the XML files in Netscape 7.0 on my own machine...
4
4287
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. All that I want is to replace node names with a matching value in the lookup table and place the result into an field attribute pair: Example: id...
1
2031
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
2066
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 id="DEF"></client> </position>
2
22756
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 in the attribute of an element. Instead of using the <xsl:attribute> element, you can simply place the xpath in the attribute itself. The most...
1
2203
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 like this: <DataSet ID="-5480"> <ObsGroup> <ClsItem name="AGE">2099</ClsItem> <ClsItem name="COMB_DATA">20</ClsItem> <ClsItem...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7665
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.