Re: [xsl] get the first of the following with Attribute equals

Subject: Re: [xsl] get the first of the following with Attribute equals
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 04 Feb 2003 12:02:04 -0500

One solution to your problem is to relate each 'paragraphe' element to the 'title' element to which it "belongs" using a key:

<xsl:key name="paras-by-title" match="element[@type='paragraphe']"

Then instead of selecting "following::element[@type='paragraphe']" in your for-each, generate your output for your title, and then select the paragraphs that belong to it using the key function:

select="key('paras-by-title', generate-id())"

which returns only paragraph elements that follow the title without any intervening title elements (which would come in on the following or following-sibling axes).

This method is described in the XSL FAQ under the heading "Flat file transformation":

I hope that helps!

At 10:57 AM 2/4/2003, you wrote:
Hi, I have the following XML:

<document xmlns:fo="";>
      <element type="title" position="1">text1</element>
      <element type="paragraphe" position="2">text2</element>
      <element type="paragraphe" position="3">text3</element>
      <element type="title" position="4">text4</element>
      <element type="paragraphe" position="5">text5</element>
      <element type="paragraphe" position="6">text6</element>
      <element type="title" position="7">text7</element>
      <element type="paragraphe" position="9">text9</element>
      <element type="paragraphe" position="10">text10</element>
      <element type="title" position="11">text11</element>
      <element type="paragraphe" position="12">text12</element>
      <element type="paragraphe" position="13">text13</element>


I want to have only the *first *following with the attribute Type = title
or with my test : <xsl:if test="./@position &lt; following::element [@type='title']/@position"> I have : <document xmlns:fo="";>
What I want is only text2 and text 3, I don't want text5 --> text10 with this title

Any Idea? I become nuts....

Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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

XSL-List info and archive:

Current Thread