Re: trying to build an xpath query...

Discussion in 'XML' started by Michael Dahlquist, Jul 9, 2003.

  1. Marrow -

    This helps a ton. Perfect. Of course my example didn't end up being
    quite accurate, but that just meant I had to figure the rest out on my
    own. It's better that way. Thanks for your help -

    Michael



    But if you want to include the skipped <b> elements as being those that
    are
    part of the preceding <b> with a 'marker-' then you need to tweak the
    key a
    bit too, e.g.

    == XSL2 =====================================
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="html" indent="yes"/>
    <xsl:key name="kBGrouped" match="a/*[not(self::b) or
    self::b[not(m/@id[starts-with(.,'marker-')])]]"
    use="generate-id(preceding-sibling::b[m/@id[starts-with(.,'marker-')]][1
    ])"/
    >

    <xsl:template match="a">
    <html>
    <body>
    <xsl:apply-templates select="b[m/@id[starts-with(.,'marker-')]]"/>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="b">
    <h2>
    <xsl:text>B title: </xsl:text>
    <xsl:value-of select="."/>
    </h2>
    <!-- now do all the elements following this <b> -->
    <xsl:apply-templates select="key('kBGrouped',generate-id())"
    mode="after-b"/>
    </xsl:template>

    <xsl:template match="*" mode="after-b">
    <div>
    <xsl:text>Element: </xsl:text>
    <xsl:value-of select="name()"/>
    <xsl:text> (</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>)</xsl:text>
    <!-- if you want to process the children of the elements -->
    <!-- following the <b> then do an <xsl:apply-templates> -->
    <!-- here and provide templates for them. -->
    </div>
    </xsl:template>
    </xsl:stylesheet>
    == end of XSL2 ==============================

    Hope this helps
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Michael Dahlquist, Jul 9, 2003
    #1
    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. Learner
    Replies:
    1
    Views:
    973
    Marina Levit [MVP]
    Jan 30, 2006
  2. Anonymous
    Replies:
    0
    Views:
    1,439
    Anonymous
    Oct 13, 2005
  3. Michael Dahlquist

    trying to build an xpath query...

    Michael Dahlquist, Jul 1, 2003, in forum: XML
    Replies:
    0
    Views:
    786
    Michael Dahlquist
    Jul 1, 2003
  4. Michael Dahlquist

    Re: trying to build an xpath query...

    Michael Dahlquist, Jul 7, 2003, in forum: XML
    Replies:
    0
    Views:
    830
    Michael Dahlquist
    Jul 7, 2003
  5. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    778
    David Gordon
    May 18, 2005
Loading...

Share This Page