[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Predicates vs. Axes

Subject: Re: Predicates vs. Axes
From: Peter Davis <pdavis152@xxxxxxxxx>
Date: Mon, 3 Jun 2002 14:20:06 -0700
preceding xsl
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 03 June 2002 12:49, Joerg Heinicke wrote:
> use preceding-sibling and following-sibling axes.

and Michael Peet wrote:
> >        <node id="5"/>
> >        <node id="6"/>
> >        <d>
> >          <node id="7"/>
...
> > For example, if node 6 is marked current, 5 and 7 will be 
> > preceding and following, respectively.

Unfortunately, Michael, you will have to revise this requirement if you want 
to use preceding-sibling and following-sibling axes.  It might be that the 
only way to do it is with a recursive template like this:

<xsl:template match="node[current='true']">
  <xsl:call-template name="find-current-preceding"/>
  <xsl:call-template name="find-current-following"/>
</xsl:template>

<xsl:template name="find-current-preceding">
  <xsl:variable name="preceding" select="parent::*[1] | preceding::*[1]"/>
  <xsl:choose>
    <xsl:when test="$preceding[last()]/self::b">
      Found no preceding node.
    </xsl:when>
    <xsl:when test="$preceding[last()]/self::node">
      Found preceding node: <xsl:copy-of select="$preceding[last()]"/>
    </xsl:when>
    <xsl:otherwise>
      <!-- change the context node to 
        $preceding[last()] for the call-template -->
      <xsl:for-each select="$preceding[last()]">
        <xsl:call-template name="find-current-preceding"/>
      </xsl:for-each>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="find-current-following">  
  <xsl:choose>
    <xsl:when test="following::*[1]/self::b">
      Found no following node.
    </xsl:when>
    <xsl:when test="following::*[1]/self::node">
      Found following node: <xsl:copy-of select="following::*[1]"/>
    </xsl:when>
    <xsl:otherwise>
      <!-- change the context node to 
        $preceding[last()] for the call-template -->
      <xsl:for-each select="following::*[1]">
        <xsl:call-template name="find-current-following"/>
      </xsl:for-each>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Note that I haven't tested this at all, so I hope I haven't made some 
fundamental error in logic.

The hard part is with the preceding axis, since it does not include nodes on 
the ancestor axis.  I'm attempting (hopefully successfully, again I haven't 
tested this) to combine the nearest elements on the preceding and parent axes 
and then test the element that comes last in document order.

Once you get the preceding|parent and following elements, just test whether 
the element is a <b> or not.  If it is a <b>, then stop.  If it is a <node>, 
then output success.  If it is anything else (like a <c>, <d>, or <e>), then 
try again.

- -- 
Peter Davis
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8+92GNSZCJx7tYycRAss+AJ9e43gP2GaAC7uFc7avRgpn+10XjwCgrNcQ
SPmhyyJIjo+78dPiP3pH8GM=
=bp/H
-----END PGP SIGNATURE-----


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.