Replacement for "first-of-type", etc.

Subject: Replacement for "first-of-type", etc.
From: Michel Goossens <Michel.Goossens@xxxxxxx>
Date: Fri, 23 Apr 1999 17:32:30 +0200 (METDST)
I would like to select all child element types that occur only once.
In the previous draft I wrote something like
<xsl-template match="*[first-of-type() and last-of-type()]">
...

But I do not see an evident replacement in the current (April 22) draft.

Here is an example:

Consider the following XML file:

<article>
  <title>This is the article's title</title>
  <author>Author One</author>
  <author>Author Two</author>
  <abstract>A <emph>short</emph> description of the contents</abstract>
  <section>
    <stitle>First section title</stitle>
    <par>The first paragraph for this section.</par>
    <par>A paragraph with <emph>emphasised</emph> text.</par>
    <par>This is the end of the section.</par>
  </section>
  <section>
    <stitle>Second section title</stitle>
    <par>This is <emph>emph</emph> and <emph>more emph</emph> text.</par>
    <par>Paragraph with <bold>bold</bold> and
         <emph>emphasised</emph> text.</par>
  </section>
</article>

with the following XSL stylesheet:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";>
<xsl:template match="/">
  <xsl:text>(*root*)</xsl:text>
  <xsl:apply-templates/>
  <xsl:text>(/*root*)</xsl:text>
</xsl:template>
<xsl:template match="*" priority="-1">
  <xsl:text>(*)</xsl:text>
  <xsl:apply-templates/>
  <xsl:text>(/*)</xsl:text>
</xsl:template>
<xsl:template match="*[position()=1 and position()=last()]" priority="1">
  <xsl:text>($)</xsl:text>
  <xsl:apply-templates/>
  <xsl:text>(/$)</xsl:text>
</xsl:template>
</xsl:stylesheet>

Then I obtain with xt the following output (which is correct):

(*root*)($)
  (*)This is the article's title(/*)
  (*)Author One(/*)
  (*)Author Two(/*)
  (*)A ($)short(/$) description of the contents(/*)
  (*)
    (*)First section title(/*)
    (*)The first paragraph for this section.(/*)
    (*)A paragraph with ($)emphasised(/$) text.(/*)
    (*)This is the end of the section.(/*)
  (/*)
  (*)
    (*)Second section title(/*)
    (*)This is (*)emph(/*) and (*)more emph(/*) text.(/*)
    (*)Paragraph with (*)bold(/*) and
         (*)emphasised(/*) text.(/*)
  (/*)
(/$)

But I would like to select the <title>, <abstract>, and <stitle>
elements, plus the <bold> and <emph> elements in the last <par> element
since they are unique child elements of their respective types for the
parent node. I tried to understand how to work with the preceding and
following-sibling axes, but the syntax I should use escapes me.
Can somebody explain how I could express my match pattern? Thanks. m

----------------------------------------------------
Dr. Michel Goossens         Phone: (+41 22) 767-5028
IT Division                 Fax:   (+41 22) 767-8630
CERN                        Email:  goossens@xxxxxxx
CH-1211 Geneva 23    F-01631 CERN Cedex
Switzerland          France






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


Current Thread