xsl-list
[Top] [All Lists]

Re: [xsl] Re: xhtml via xslt failure

2013-12-17 13:43:02
Hi again,

On Tue, Dec 17, 2013 at 2:02 PM, Martin Holmes <mholmes(_at_)uvic(_dot_)ca> 
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 -->
  <p>
    <xsl:apply-templates select="author"/>
  </p>
</xsl:template>

<xsl:template match="author">
  <!-- we punctuate according to rules of displaying a series of
authors (adjust to requirements) -->
  <xsl:choose>
    <!-- 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>
  </xsl:choose>
  <!-- processing child nodes, values of text contents will be emitted
by default -->
  <xsl:apply-templates/>
</xsl:template>

I hope that helps.

Cheers, Wendell

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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--