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

Re: Implementing XPointer Resolution With saxon:evalua

Subject: Re: Implementing XPointer Resolution With saxon:evaluate()
From: "W. Eliot Kimber" <eliot@xxxxxxxxxx>
Date: Wed, 14 Aug 2002 17:10:49 -0500
saxon xpointer
Jeni Tennison wrote:
> 
> Hi Eliot,
> 
> Sorry, I should have given more clues...

Ok, here is a new version that appears to work correctly for all
possible in-document links.

Thanks for all the help.

Cheers,

Eliot

<?xml version='1.0'?>
<!-- Copyright (c) 2002 ISOGEN International 

     This style sheet serves as a reference implementation of the
XIndirect facility.
     It may be used without restriction as long as this copyright
statement is
     preserved. This software is provided AS-IS without any warranty,
express or implied.

  -->
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xlink="http://www.w3.org/TR/xlink"
  xmlns:xindr="http://www.isogen.com/papers/xindirection.xml"
  xmlns:xindrf="http://www.isogen.com/functions/xindirection"
  xmlns:saxon="http://icl.com/saxon"
  xmlns:func="http://exslt.org/functions"
  xmlns:fcommon="http://exslt.org/common"
  extension-element-prefixes="func xindrf"
>

<func:function name="xindrf:resolve-xpointer">
  <xsl:param name="pointer-node"/><!-- The Element node that exhibits
the XPointer to be resolved -->
  <xsl:param name="indirector-treatment">as-indirector</xsl:param>
  <xsl:variable name="indirector-treatment-str"
select="string($indirector-treatment)"/>
  <xsl:variable name="xpointer">
    <xsl:choose>
      <xsl:when test="starts-with($pointer-node/@href,'#')">
        <xsl:value-of select="substring($pointer-node/@href, 2)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$pointer-node/@href"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:for-each select="$pointer-node">
    <!-- Setting the context to the pointer node so that relative URLs
are resolved
         relative to the pointer node by saxon:evaluate() -->
    <xsl:choose>
      <xsl:when test="$xpointer != ''">     
        <xsl:variable name="direct-result-set"
select="saxon:evaluate($xpointer)"/>
        <xsl:if test="string($direct-result-set) = ''">
          <xsl:message>*** XIndirect warning: XPointer '<xsl:value-of
select="$xpointer"/>' failed to address any nodes.</xsl:message>
        </xsl:if>
        <func:result
select="xindrf:resolve-indirectors($direct-result-set,
$indirector-treatment-str)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>
  *** XIndirect error: $xpointer value is '' in resolve-xpointer.
          <func:result select="/.."/>
        </xsl:message>
      </xsl:otherwise>
    </xsl:choose>  
  </xsl:for-each>
</func:function>

<func:function name="xindrf:resolve-indirectors">
  <xsl:param name="pointer-node-set" select="/.."/>
  <xsl:param name="indirector-treatment">as-indirector</xsl:param>
  <xsl:variable name="indirector-treatment-str"
select="string($indirector-treatment)"/>
  <xsl:choose>
    <xsl:when test="$pointer-node-set">
      <xsl:variable name="car" select="$pointer-node-set[1]"/>
      <xsl:variable name="cdr" select="$pointer-node-set[position() &gt;
1]"/>
      <xsl:choose>
        <xsl:when test="$car[self::xindr:indirector] and 
                        ($indirector-treatment-str != 'as-resource')">
          <xsl:variable name="rns" 
                select="xindrf:resolve-xpointer($car,
$car/@indirector-treatment) |
                        xindrf:resolve-indirectors($cdr,
$indirector-treatment-str)"/>
          <func:result select="$rns"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:variable name="rest"
select="xindrf:resolve-indirectors($cdr, $indirector-treatment-str)"/>
          <xsl:variable name="rns" 
              select="$car | $rest"/>
          <func:result select="$rns"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <func:result select="/.."/>
    </xsl:otherwise>
  </xsl:choose>
</func:function>
</xsl:stylesheet>

-- 
W. Eliot Kimber, eliot@xxxxxxxxxx
Consultant, ISOGEN International

1016 La Posada Dr., Suite 240
Austin, TX  78752 Phone: 512.656.4139

 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-2013 All Rights Reserved.