473,322 Members | 1,718 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,322 software developers and data experts.

Using Select with multiple separate nodes in XSL

I have two nodes that both exist underneath the root node. They are
linked, however, in the sense that one of the nodes contains a copy of
an id that is used to refer to the other. However, when I try create a
param using this search critieria it can never seem to locate what I
am looking for. For example, check out the following XML file:
-------------------------
<data>
<aBlock id="1">
<tmpdata>
<stringType>Hi</stringType>
</tmpdata>
<reference>
<id>3</id>
</reference>
</aBlock>
<bBlock id="2">
<message>Wrong one</message>
</bBlock>
<bBlock id="3">
<message>Right One</message>
</bBlock>
</data>
-------------------------

with its corresponding stylesheet:
-------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head><title>Test</title></head>
<body>
Test output:<br/>
<xsl:for-each select="/data/aBlock">
<xsl:apply-templates mode="subData" select="."/>
</xsl:for-each>
</body>
</html>
</xsl:template>

<xsl:template mode="subData" match="aBlock">
<xsl:param name="bBlockRef" select="/data/bBlock[@id='2']"/><br />
<xsl:value-of select="./reference"/><br/>
<!-- Problem Statement -->
The Message is: <xsl:value-of
select="/bBlock[@id=./reference]/message"/>
</xsl:template>
</xsl:stylesheet>
-------------------------

The result looks this:
-------------------------
Test output:

3
The Message is:
-------------------------

So the problem is that trying to match the id attribute to a subNode
in the current node isn't working. I don't know if this is because my
syntax is correct (but the preceding value-of expression shows that it
is functional) or if it is because I am trying to perform illegal
behavior in XSL, or what.

But if anyone could help me out- I would be in your debt.

Randeep Walia
Jul 20 '05 #1
2 2858


RanDeep wrote:
I have two nodes that both exist underneath the root node. They are
linked, however, in the sense that one of the nodes contains a copy of
an id that is used to refer to the other. However, when I try create a
param using this search critieria it can never seem to locate what I
am looking for. For example, check out the following XML file:
-------------------------
<data>
<aBlock id="1">
<tmpdata>
<stringType>Hi</stringType>
</tmpdata>
<reference>
<id>3</id>
</reference>
</aBlock>
<bBlock id="2">
<message>Wrong one</message>
</bBlock>
<bBlock id="3">
<message>Right One</message>
</bBlock>
</data>
-------------------------

with its corresponding stylesheet:
-------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head><title>Test</title></head>
<body>
Test output:<br/>
<xsl:for-each select="/data/aBlock">
<xsl:apply-templates mode="subData" select="."/>
</xsl:for-each>
</body>
</html>
</xsl:template>

<xsl:template mode="subData" match="aBlock">
<xsl:param name="bBlockRef" select="/data/bBlock[@id='2']"/><br />
<xsl:value-of select="./reference"/><br/>
<!-- Problem Statement -->
The Message is: <xsl:value-of
select="/bBlock[@id=./reference]/message"/>
</xsl:template>
</xsl:stylesheet>
-------------------------

The result looks this:
-------------------------
Test output:

3
The Message is:
-------------------------

So the problem is that trying to match the id attribute to a subNode
in the current node isn't working. I don't know if this is because my
syntax is correct (but the preceding value-of expression shows that it
is functional) or if it is because I am trying to perform illegal
behavior in XSL, or what.

But if anyone could help me out- I would be in your debt.


You could store the value in a variable and use that, here is an example
stylesheet

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head><title>Test</title></head>
<body>
Test output:<br/>
<xsl:for-each select="/data/aBlock">
<xsl:apply-templates mode="subData" select="."/>
</xsl:for-each>
</body>
</html>
</xsl:template>

<xsl:template mode="subData" match="aBlock">
<xsl:variable name="ref" select="reference/id" />
<xsl:value-of select="$ref"/><br/>
<!-- Problem Statement -->
The Message is: <xsl:value-of
select="/data/bBlock[@id=$ref]/message"/>
</xsl:template>
</xsl:stylesheet>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin Honnen <Ma***********@t-online.de> wrote in message news:<3f********@olaf.komtel.net>...
RanDeep wrote:
I have two nodes that both exist underneath the root node. They are
linked, however, in the sense that one of the nodes contains a copy of
an id that is used to refer to the other. However, when I try create a
param using this search critieria it can never seem to locate what I
am looking for. For example, check out the following XML file:
-------------------------
<xsl:template mode="subData" match="aBlock">
<xsl:param name="bBlockRef" select="/data/bBlock[@id='2']"/><br />
<xsl:value-of select="./reference"/><br/>
<!-- Problem Statement -->
The Message is: <xsl:value-of
select="/bBlock[@id=./reference]/message"/>
</xsl:template>
</xsl:stylesheet>
-------------------------


You could store the value in a variable and use that, here is an example
stylesheet

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head><title>Test</title></head>
<body>
Test output:<br/>
<xsl:for-each select="/data/aBlock">
<xsl:apply-templates mode="subData" select="."/>
</xsl:for-each>
</body>
</html>
</xsl:template>

<xsl:template mode="subData" match="aBlock">
<xsl:variable name="ref" select="reference/id" />
<xsl:value-of select="$ref"/><br/>
<!-- Problem Statement -->
The Message is: <xsl:value-of
select="/data/bBlock[@id=$ref]/message"/>
</xsl:template>
</xsl:stylesheet>


Using a temp variable is actually the work-around I am using
currently, but my question is, why do I have to use it at all? I tried
doing some research to find out if this was standard behavior or not
but found nothing.

I guess I am looking for the technical reason for this behavior- why
does XSL not allow attribute comparisons in select statements between
two separate nodes, and whether or not that behavior will be
consistent in future XSL versions.

Randeep
Jul 20 '05 #3

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

Similar topics

5
by: Colman | last post by:
Howdy all! I guess I'm a newbie, because I am stumped (or maybe just too durned tired). Here's what I got... CREATE TABLE `nodecat_map` ( `nodecat_id` mediumint(8) unsigned NOT NULL...
4
by: Tristan Miller | last post by:
Greetings. I would like to produce a static multilingual website in XHTML. Is it possible to specify each web page in its own XML file, but have all of the translations encapsulated in that one...
3
by: Michael | last post by:
Hello, I am creating an XSL that is going to create a report from XML we recieve from another system. The XML would look like: <report> <page> <header1> <data1>asdf</data1>...
7
by: pfa | last post by:
I have a udf which returns a table. I was hoping to access the NEXTVAL from a sequence to affect the logic flow and consequently the return result. I'm using a LANGUAGE C type function. Here's...
3
by: Hazz | last post by:
I am just beginning to design a Treeview display (winforms) for wine regions. Problem. Some wine growing regions belong to two counties. Eg. Carneros is in both Napa and Sonoma Counties. Although...
2
by: nick_tucker | last post by:
Hi, I am very new to XML and XPATH. I have made a sample XML fileto ask my question. <?xml version="1.0" encoding="utf-8"?> <Test> <A> <B> <C> <D>
4
by: Turban | last post by:
When I attempt to run the following code: protected void NavigationTreeView_TreeNodePopulate(object sender, TreeNodeEventArgs e) { TreeNode tn1 = new TreeNode("node1","node1"); TreeNode tn2 =...
6
by: greek_bill | last post by:
Hi, I'm interested in developing an application that needs to run on more than one operating system. Naturally, a lot of the code will be shared between the various OSs, with OS specific...
1
by: karthee | last post by:
I am creating a custom treeview with multiple selection, if i select multiple nodes and right click, the selection is disappearing, i tried with somany things like on mouse click my code is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.