Using Select with multiple separate nodes in XSL

Discussion in 'XML' started by RanDeep, Sep 25, 2003.

  1. RanDeep

    RanDeep Guest

    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
     
    RanDeep, Sep 25, 2003
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Sep 26, 2003
    #2
    1. Advertising

  3. RanDeep

    RanDeep Guest

    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">
    > > <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
     
    RanDeep, Sep 26, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael

    Select multiple nodes in XSL

    Michael, Dec 2, 2004, in forum: XML
    Replies:
    3
    Views:
    1,706
    Morris M. Keesan
    Dec 3, 2004
  2. Replies:
    2
    Views:
    403
  3. Frank Fredstone
    Replies:
    1
    Views:
    460
    Jean-Francois Briere
    Jun 27, 2006
  4. th3dude
    Replies:
    0
    Views:
    439
    th3dude
    Jan 3, 2007
  5. cosmo
    Replies:
    0
    Views:
    1,441
    cosmo
    Oct 4, 2008
Loading...

Share This Page