[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] find the following sibling of my parent
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|