[xsl] question about apply-templates / following-sibling

Subject: [xsl] question about apply-templates / following-sibling
From: Marko Petersen <lg002237@xxxxxxxxxxxxxxxx>
Date: Thu, 12 Dec 2002 15:58:22 +0100
Hi,

I would like to update some XML documents by inserting an element.
The documents are vaild to the DocBook DTD, but the following is a
simple subset which shows the problem I have:

<!ELEMENT chapter
    (   beginpage?, chapterinfo?, title
        (index)*,
        (
          (
            (para | %chapter.elements; | beginpage)+,
	  (section* | simplesect*)
          )   |
	(section+ | simplesect+)
        ),
        (index)*,
    )
>

The entity chapter.elements contains over 50 elements (but not index,
section or simplesect).
In my documents I want to insert a para element at the last position
where it is allowed. The document should still be valid. If the chapter contains
a section or simplesect, the para can be inserted right before it, but if not, it
has to be the last element of chapter, only followed by index elements if
present. For example:


<chapter>
  <beginpage pagenum="1">
  <title>test</title>
  <index>index stuff</index>
  <index>index stuff</index>
  <para>text1</para>
  <beginpage pagenum="2">
  <!-- the new para should be here -->
  <index>index stuff</index>
  <index>index stuff</index>
</chapter>

I tried to use apply-templates, but I do not know a good way to select the first
optional index elements without selecting the ones that could be at the end
of the chapter. I need something like "all index elements where only index elements
are following".


<xsl:template match="chapter">
   <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <!-- copy everything before new para, including index elements -->
      <para>New para</para>
      <!-- copy everything after new para, including index elements  -->
   </xsl:copy>
</xsl:template>

Any ideas how to do this? I tried something with following-sibling, but it does not work.

Thanks and greetings,

Marko


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread