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

find the following sibling of my parent

Subject: find the following sibling of my parent
From: Perry Roland <pdr4h@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 26 Apr 2000 17:18:00 -0400
parent following sibling
Allow me to give some background first.  Then the question.

I'm attempting to write stylesheets to deliver a document in 
chunks.  Since this is a TEI document, the chunks are <div>s.

I've got a stylesheet which creates a table of contents with
links which call the second stylesheet.  To this second
stylesheet I pass the id [generated using generate-id()] of the 
div I want to see.  So far, so good.

Now I want to be able to select the next div.  As long as the
current div has a following sibling, I'm OK.  But when I'm buried
down a couple of levels inside a bunch of nested divs and I'm at the
end of this level of hierarchy, how can I get the following sibling of
my parent element?

For example --

<div type="chapter" n="1">
     <div type="journal">
          <div type="entry">TEXT IN HERE
               <div type="letter">TEXT IN HERE</div>
          </div>
          <div type="entry">TEXT IN HERE</div>
          <div type="entry">TEXT IN HERE</div>
     </div>
</div>
<div type="chapter" n="2">
	ETC.

When I'm in the letter, I want to generate a link to the 2nd entry div
of the journal.  Similarly, when I'm in the journal div, I want a link
to chapter 2.  The last entry div of the journal also contain a link to
chapter 2.

Here's part of my stylesheet --

<xsl:template match="div">
        <xsl:apply-templates/>
        <xsl:choose>
        <xsl:when test="following-sibling::*[position()=1]">
                <xsl:element name="A">
                <xsl:attribute name="href">http://blah...passedid=
<xsl:value-of select="generate-id(following-sibling::*[position()=1])"/>
		</xsl:attribute>NEXT</xsl:element>
        </xsl:when>
        <xsl:otherwise>
                <xsl:call-template name="parentnext">
                        <xsl:with-param name="context" select="parent"/>
                </xsl:call-template>
        </xsl:otherwise>
        </xsl:choose>
</xsl:template>

<xsl:template name="parentnext">
        <xsl:param name="context"></xsl:param>
        <xsl:choose>
        <xsl:when test="$context::following-sibling::*[position()=1]">
                <xsl:element name="A">
                <xsl:attribute name="href">http://...passedid=<xsl:value-of
select="generate-id($context::following-sibling::*[position()=1])"/>
</xsl:attribute>NEXT</xsl:element>
        </xsl:when>
	<xsl:otherwise>
                <xsl:variable name="newcontext">
                        <xsl:value-of select="concat($context,'::parent')"/>
                </xsl:variable>
                <xsl:call-template name="parentnext">
                        <xsl:with-param name="context" select="$newcontent"/>
                </xsl:call-template>
        </xsl:otherwise>
        </xsl:choose>
</xsl:template>

The logic goes -- When I've got a following-sibling generate a link to it,
otherwise look recursively backwards up the hierarchy for a
following-sibling of one of my ancestors.  I must be doing something wrong,
however, because saxon complains about $context in the select statement
with the following error message --
	Error in expression $context::following-sibling::*[position()=1]:
	expected "<name>", found "<axis>()"

Any help is greatly appreciated.

--
perry


 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.