Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Using Select with multiple separate nodes in XSL

Reply
Thread Tools

Using Select with multiple separate nodes in XSL

 
 
RanDeep
Guest
Posts: n/a
 
      09-25-2003
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"
xmlnssl="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">
<xslaram 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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      09-26-2003


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"
> xmlnssl="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">
> <xslaram 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"
xmlnssl="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/

 
Reply With Quote
 
 
 
 
RanDeep
Guest
Posts: n/a
 
      09-26-2003
Martin Honnen <> wrote in message news:<3f740804$>...
> 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">
> > <xslaram 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"
> xmlnssl="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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a variable to tell xsl:for-each which nodes to select cosmo XML 0 10-04-2008 06:14 AM
Newbie: Only select certain nodes in an xsl:template match David Cater XML 6 05-31-2007 06:04 AM
Dataset Question - Odd results with single xml nodes vs multiple nodes th3dude ASP .Net 0 01-03-2007 03:24 PM
XSL select emplty nodes ree32@hotmail.com XML 2 06-28-2005 10:33 PM
Select multiple nodes in XSL Michael XML 3 12-03-2004 08:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57