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
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