Re: [xsl] How to get page range within a group

Subject: Re: [xsl] How to get page range within a group
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 12 Sep 2008 09:36:55 -0400
J.S.,

At 01:38 AM 9/12/2008, you wrote:
Hi All,
I am not able to get the appropriate result. Can anybody let me know about the mistake I am doing. I want a page range within <doc>.

...


<xsl:if test="//doc//pb[position()=1]">
<xsl:variable name="fpage" select="substring-after(//doc//pb[position()=1]/@n,'-')"/>

...


This isn't working for you since the expression //doc//pb[position()=1] does not return what you think it does.

It may appear it should return the first 'pb' element appearing inside each 'doc' element in the document, but this isn't so. The semantics of "//" is not (as it is commonly glossed) "all the nodes (or elements) all the way down the tree". It is an abbreviation for "/descendant-or-self::node()/", which in itself is not a complete XPath expression, but must be completed by adding an axis and node test. In particular, when you say "//pb" you are implicitly adding the child:: axis (as always when no axis is given explicitly) along with the "pb" node test. That is, "//pb" is short for "/descendant-or-self::node()/child::pb".

This is crucial since it means that //pb[1] does not mean "the first 'pb' descendant" but "the first pb child of any descendant".

If you actually want the first descendant, the easiest way to get that is (in your case) "//doc/descendant::pb[1]".

You may have other problems (I haven't shaken the code out completely), but nothing will work right as long as this isn't correct.

I hope that helps,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread