A little XSL help please?

Discussion in 'XML' started by Dennis, May 1, 2008.

  1. Dennis

    Dennis Guest

    [[Sorry I couldn't think of a better subject for this rookie question.]]

    In my .xml I have something like:

    <root>
    <parent>
    ...
    <child>
    <keynode>thekey</keynode>
    </child>
    </parent>
    ...
    <parent>
    <keynode>thekey</keynode>
    <valuenode>thevalue</valuenode>
    ...
    </parent>
    </root>

    In english, what I would like to do in my .xsl is this:

    When processing each /root/parent/child, use the value of keynode
    ('thekey') to look up a /root/parent somewhere else in the .xml with a
    keynode which matches ... and retrieve the corresponding valuenode
    ('thevalue').

    Is this possible?

    P.S. I can manage the xsl:for-each part.

    TIA,

    --

    Dennis
     
    Dennis, May 1, 2008
    #1
    1. Advertising

  2. Dennis wrote:
    > [[Sorry I couldn't think of a better subject for this rookie question.]]
    >
    > In my .xml I have something like:
    >
    > <root>
    > <parent>
    > ...
    > <child>
    > <keynode>thekey</keynode>
    > </child>
    > </parent>
    > ...
    > <parent>
    > <keynode>thekey</keynode>
    > <valuenode>thevalue</valuenode>
    > ...
    > </parent>
    > </root>
    >
    > In english, what I would like to do in my .xsl is this:
    >
    > When processing each /root/parent/child, use the value of keynode
    > ('thekey') to look up a /root/parent somewhere else in the .xml with a
    > keynode which matches ... and retrieve the corresponding valuenode
    > ('thevalue').
    >
    > Is this possible?


    Sure
    <xsl:template match="root/parent/child">
    <xsl:value-of select="../parent[keynode =
    current()/keynode]/valuenode"/>
    </xsl:template>




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, May 1, 2008
    #2
    1. Advertising

  3. Dennis

    Dennis Guest

    On Thu, 01 May 2008 18:11:55 +0200, Martin Honnen <>
    wrote:

    >Dennis wrote:
    >> [[Sorry I couldn't think of a better subject for this rookie question.]]
    >>
    >> In my .xml I have something like:
    >>
    >> <root>
    >> <parent>
    >> ...
    >> <child>
    >> <keynode>thekey</keynode>
    >> </child>
    >> </parent>
    >> ...
    >> <parent>
    >> <keynode>thekey</keynode>
    >> <valuenode>thevalue</valuenode>
    >> ...
    >> </parent>
    >> </root>
    >>
    >> In english, what I would like to do in my .xsl is this:
    >>
    >> When processing each /root/parent/child, use the value of keynode
    >> ('thekey') to look up a /root/parent somewhere else in the .xml with a
    >> keynode which matches ... and retrieve the corresponding valuenode
    >> ('thevalue').
    >>
    >> Is this possible?

    >
    >Sure
    > <xsl:template match="root/parent/child">
    > <xsl:value-of select="../parent[keynode =
    >current()/keynode]/valuenode"/>
    > </xsl:template>


    Thanks! I'll give it a whirl...

    --

    Dennis
     
    Dennis, May 1, 2008
    #3
  4. Dennis wrote:

    >> <xsl:template match="root/parent/child">
    >> <xsl:value-of select="../parent[keynode =
    >> current()/keynode]/valuenode"/>
    >> </xsl:template>

    >
    > Thanks! I'll give it a whirl...


    Should be
    <xsl:value-of select="../../parent[keynode = current()/keynode]/valuenode"/>
    actually.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, May 1, 2008
    #4
  5. Dennis

    Dennis Guest

    On Thu, 01 May 2008 19:11:51 +0200, Martin Honnen <>
    wrote:

    >Dennis wrote:
    >
    >>> <xsl:template match="root/parent/child">
    >>> <xsl:value-of select="../parent[keynode =
    >>> current()/keynode]/valuenode"/>
    >>> </xsl:template>

    >>
    >> Thanks! I'll give it a whirl...

    >
    >Should be
    ><xsl:value-of select="../../parent[keynode = current()/keynode]/valuenode"/>
    >actually.


    OK.

    Can you recommend a good online resource for beginners. I have a
    programming background so I pick up on things quickly. I have been using
    www.w3schools.com and just googling for answers to my questions, but I
    don't see anyplace that I would call a comprehensive reference site with
    good examples.

    Thanks,

    --

    Dennis
     
    Dennis, May 1, 2008
    #5
  6. Many good tutorials/articles are available at http://www.ibm.com/xml.

    For terse but enlightening examples of less-than-obvious patterns, see
    the XSLT FAQ at http://www.dpawson.co.uk/xsl/sect2/sect21.html

    (I've heard more complaints about the w3schools website than praise for
    it. You might want to take its suggestions with a grain of salt...)
     
    Joseph J. Kesselman, May 1, 2008
    #6
    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. Replies:
    1
    Views:
    3,636
    A. Bolmarcich
    May 27, 2005
  2. KK
    Replies:
    2
    Views:
    646
    Big Brian
    Oct 14, 2003
  3. Brett
    Replies:
    4
    Views:
    829
    Brett
    Jun 5, 2007
  4. ThaDoctor
    Replies:
    3
    Views:
    392
    Alan Woodland
    Sep 28, 2007
  5. Daniel
    Replies:
    1
    Views:
    220
    Bart van Ingen Schenau
    Jul 9, 2013
Loading...

Share This Page