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

Re: postion gives me 2 instead of 1

Subject: Re: postion gives me 2 instead of 1
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 20 Jun 2003 09:54:59 +0100
2 instead of 1
Hi Paul,

> I want to put a number just in front of the first paragraphs in each
> listitem.
>
> Here is a try from my xslt stylesheet:
>
>     <xsl:template match = "listitem/para[1]">
>         <block>
>             <xsl:value-of select = "../@number"/>
>             <xsl:apply-templates/>
>         </block>
>     </xsl:template>
>
> This doesn't work. For some reason, xslt gives the position number
> as 2 for the first paragraph.

The above template tells the processor:

 "Whenever you're told to process the first <para> element within a
  <listitem> element, here is what you do: create a <block> element;
  as the content of the <block> element, first insert the value of the
  number attribute of the <para> element's parent <listitem> element,
  and then apply templates to the content of the <para> element."

The reason that the first paragraph in the second list item is getting
the number 2 is that its parent <listitem> element's number attribute
has the value '2'. The first paragraph in the first list item gets the
number 1 because its parent <listitem> element's number attribute has
the value '1'.

> For example, this styelsheet works, but I don't know why:
>
> <xsl:template match = "listitem/para">
>        <xsl:if test = "position() = 2">
>         <block>
>             <xsl:value-of select = "../@number"/>
>             <xsl:apply-templates/>
>         </block>
>        </xsl:if>
> </xsl:template>

The above template tells the processor:

 "Whenever you're told to process the a <para> element within a
  <listitem> element, here is what you do: if this is the second
  <para> element that you've been told to process, then create a
  <block> element; as the content of the <block> element, first insert
  the value of the number attribute of the <para> element's parent
  <listitem> element, and then apply templates to the content of the
  <para> element."

What this template gives you depends on how you select the <para>
elements for processing. Assuming you don't have any other templates,
or that you have a template like:

<xsl:template match="listitem">
  <xsl:apply-templates />
</xsl:template>

then this template will generate a <block> element for the second
child of each <listitem> element. Assuming that you're not doing any
whitespace stripping, the first child of each <listitem> element is a
whitespace-only text node, and the second child is the first <para>
element within the <listitem> element.

The content of the <block> elements will be just the same as with the
previous template: the number that you're using for the paragraph
comes from the number attribute of its parent <listitem> element.

So I don't understand in what way your first template doesn't work,
given that you say that your second template does. Perhaps showing
more of the stylesheet and showing the output that you're getting
would help.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.