473,503 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xsl:for-each with special expression

Hi,

I am facing a situation where my XML looks something like below:

<shop>
<group>
<properties>
<property name="something1" value="$50"/>
<property name="something2" value="$10"/>
<property name="something3" value="$15"/>
</properties>
</group>

<group>
<properties>
<property name="something4" value="$25"/>
<property name="something5" value="$1"/>
<property name="something6" value="$4"/>
</properties>
</group>
</shop>

Now, how do I loop through the XML to only pick up value from
"something1" and "something5" in my XSL template so that my HTML will
only display those 2 values?

TIA.

Mike

Dec 7 '05 #1
2 950


cybernerdsx2 wrote:

<shop>
<group>
<properties>
<property name="something1" value="$50"/>
<property name="something2" value="$10"/>
<property name="something3" value="$15"/>
</properties>
</group>

<group>
<properties>
<property name="something4" value="$25"/>
<property name="something5" value="$1"/>
<property name="something6" value="$4"/>
</properties>
</group>
</shop>

Now, how do I loop through the XML to only pick up value from
"something1" and "something5" in my XSL template so that my HTML will
only display those 2 values?


One way is
<xsl:template match="/">
<html>
<head>
<title>Example</title>
</head>
<body>
<xsl:for-each select="shop/group/properties/property[@name =
'something1' or @name = 'something5']">
<!-- do here what you want to do with those element e.g. -->
<p><xsl:value-of select="@name" /> has value
<xsl:value-of select="@value" />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>

You simply write an XPath expression selecting a node set and then in
square brackets you can apply a predicate with a boolean expression to
filter that node set further.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 7 '05 #2
Martin Honnen wrote:


cybernerdsx2 wrote:

<shop>
<group>
<properties>
<property name="something1" value="$50"/>
<property name="something2" value="$10"/>
<property name="something3" value="$15"/>
</properties>
</group>

<group>
<properties>
<property name="something4" value="$25"/>
<property name="something5" value="$1"/>
<property name="something6" value="$4"/>
</properties>
</group>
</shop>

Now, how do I loop through the XML to only pick up value from
"something1" and "something5" in my XSL template so that my HTML will
only display those 2 values?


One way is

[snip]

The other way is to stop thinking in procedural terms about loops
unless you need to process the information out of document sequence.

<xsl:template
match="property[@name='something1' or @name='something5']">
<blink>
<xsl:value-of select="@value"/>
</blink>
</xsl:template>

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Dec 8 '05 #3

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

Similar topics

3
1425
by: deja | last post by:
Hi there, We are providing feeds via RSS/REST (query to RSS) with an attached XSL file that works quite nicely. We are now "pushing the envelope" by allowing feed-builders to build their own...
1
3263
by: j erickson | last post by:
with the following xsl and xml file, the display of the gif file with the <image/url> tag works. However, the gif file in the <description> tag using the name attribute "src" won't make the correct...
11
1896
by: Rolf Barbakken | last post by:
I have an xml with records like this one: <a:response> <a:href>http://server/public/sol/comp/1049306.eml</a:href> <a:propstat> <a:status>HTTP/1.1 200 OK</a:status> <a:prop>...
0
992
by: David Rose | last post by:
Hello I know nothing of XSL but was wondering if it was possible to do the following: Given an XML template: <template> <register TagPrefix="whatever" TagName="Template"...
0
1069
by: Wilson Wu | last post by:
Hi, How can i create a xml and xsl for more than one worksheet. Thanks Wilson
16
1831
by: Indy | last post by:
Hi, I have a XHTML input file with custom tag which specifies html fragments to include For example: <html> .... <include frag1="frag1.html" frag2="frag2.html"> More html here </include>...
3
1371
by: Al Hatch | last post by:
I have an XML file of the form: <AAA > <BBB>0001</BBB> <CCC> <DDD>0121</DDD> </CCC> <DDD> <EEE>0152</EEE> <FFF>0032</FFF>
0
1010
by: zach.taylor.12 | last post by:
Can anyone give me advice on the following? I need to create an XSLT to display some XML data in MS Word. I have tried using Dreamweaver to create the XSL. When I try to apply the XSL by using...
6
2230
by: Olagato | last post by:
I need to transform this: <urlset xmlns="http://www.google.com/schemas/sitemap/0.84"> <url> <loc>http://localhost/index.php/index./Paths-for-the-extreme-player</ loc> </url> <url>...
5
3479
by: Jason | last post by:
Hi all, Are you familiar with Safari? I have a site that works perfectly in IE6 IE7 FF2 FF3 but not in the latest Safari. When I test xsltProcessor, there is a error as following, I have dealt...
0
7084
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...
0
7458
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...
0
5578
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,...
1
5013
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...
0
4672
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...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.