[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Re: xhtml via xslt failure

Subject: Re: [xsl] Re: xhtml via xslt failure
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxx>
Date: Tue, 17 Dec 2013 14:42:49 -0500

Hi again,

On Tue, Dec 17, 2013 at 2:02 PM, Martin Holmes <mholmes@xxxxxxx> wrote:
> I think when you're getting started, it doesn't really help much to read the specifications; I'd do some
> tutorials first. The specs are hard to grasp unless you're already fairly comfortable with basic XSLT.

This is good advice.

Learner: the tests for preceding or following sibling 'author'
elements will only work within the context of children of 'book'
elements, such as the 'author' elements. Evaluated in the context of
the 'book', you never have 'author' element siblings at all (by
design), so these tests always return false.

Here is a working example. It makes assumptions that are not spelled out here.

<xsl:template match="bookstore/book">
  <!-- for the book, we want a paragraph, with only authors, no other
details; document order is retained -->
    <xsl:apply-templates select="author"/>

<xsl:template match="author">
  <!-- we punctuate according to rules of displaying a series of
authors (adjust to requirements) -->
    <!-- XPath 1.0 casts node sets to Boolean values as preceding or
sibling 'author' elements are found (or not) -->
    <xsl:when test="preceding-sibling::author and
not(following-sibling::author)"> and </xsl:when>
    <xsl:when test="preceding-sibling::author">, </xsl:when>
  <!-- processing child nodes, values of text contents will be emitted
by default -->

I hope that helps.

Cheers, Wendell

Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables

Current Thread