Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Predicates vs. Axes

From: Peter Davis <pdavis152@--------->
To:
Date: 6/3/2002 1:30:00 PM
-----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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent