[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: [newbie] What is the problem with preceding::simpl
Hi Thomas, > The problem is that if the "Next" link go well to the following > simplesect, and through chapters, the "Previous" link always give > the first simplesect of the current chapter, instead of just the > preceding simplesect. I'm using PHP4+Sablotron if it makes a > difference. The two places where you refer to the following simplesect element to create the link are when you do: <xsl:value-of select="following::simplesect/@id"/> and: <xsl:value-of select="following::simplesect/title"/> The xsl:value-of instruction gives you the string value of whatever the select attribute's expression evaluates to. In this case, the two expressions evaluate to node sets, the first containing the id attributes of all the simplesect elements that follow this one, and the second containing the title children of all the simplesect elements following this one. When the expression evaluates to a node set, as here, the xsl:value-of instruction takes the *first* of those nodes, in document order, and gives its value. So what you get is the id and title of the *first* simplesect element following this one. Now look at the similar xsl:value-of instructions for the Previous link: <xsl:value-of select="preceding::simplesect/@id"/> and: <xsl:value-of select="preceding::simplesect/title"/> Similarly, the node sets contain the id attributes and title child elements of *all* the simplesect elements that precede this one. Again, the xsl:value-of instruction takes the *first* of these nodes *in document order*. So the effect is that you get the id and the title of the first simplesect element in the document. What you wanted to get was the immediately preceding simplesect element. To do that, all you need to do is add a positional predicate in your paths: <xsl:value-of select="preceding::simplesect[1]/@id"/> and: <xsl:value-of select="preceding::simplesect[1]/title"/> How come the [1] works here? Well, when you use a positional predicate in a step that uses a reverse axis, such as the preceding axis, then the positions of the selected nodes are judged in *reverse* document order. So preceding::simplesect[1] means the immediately preceding simplesect element. You could alternatively do: <xsl:value-of select="(preceding::simplesect/@id)[last()]"/> and: <xsl:value-of select="(preceding::simplesect/title)[last()]"/> Here, the brackets around the paths ensure that the whole node set (all the ids and title elements) is used when assessing the positional predicate (if we left out the brakets, the predicate would get you the last title of every preceding simplesect element). Whenever you look at the positions of a whole node set (rather than just the nodes you're selecting in a step), you use document order. So the above paths would get you the last id and title elements from the preceding simplesect elements. Note that there is a subtle difference between the two methods I've used above. The first gets you the id and title of the simplesect immediately before this one. If the simplesect immediately before this one doesn't have an id or title, then you get nothing. The second one gets you the closest id and title of a preceding simplesect. If the simplesect immediately before this one doesn't have an id or title, then it will give you the id or title of the closest simplesect that there is. Probably you want the first kind of path. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ 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
|