Subject: Re: [xsl] postion gives me 2 instead of 1 From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 20 Jun 2003 09:54:59 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] postion gives me 2 instead of, Paul Tremblay | Thread | Re: [xsl] postion gives me 2 instea, Paul Tremblay |
RE: RE: [xsl] grouping by unique..., David . Pawson | Date | RE: [xsl] postion gives me 2 instea, Michael Kay |
Month |