A little XSL help please?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis

    #1

    A little XSL help please?

    [[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>thev alue</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
  • Martin Honnen

    #2
    Re: A little XSL help please?

    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>thev alue</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/

    Comment

    • Dennis

      #3
      Re: A little XSL help please?

      On Thu, 01 May 2008 18:11:55 +0200, Martin Honnen <mahotrash@yaho o.de>
      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>thev alue</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

      Comment

      • Martin Honnen

        #4
        Re: A little XSL help please?

        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/

        Comment

        • Dennis

          #5
          Re: A little XSL help please?

          On Thu, 01 May 2008 19:11:51 +0200, Martin Honnen <mahotrash@yaho o.de>
          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

          Comment

          • Joseph J. Kesselman

            #6
            Re: A little XSL help please?

            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...)

            Comment

            Working...