Re: [xsl] Attribute "separator" of xsl:value-of in XSLT 2.0

Subject: Re: [xsl] Attribute "separator" of xsl:value-of in XSLT 2.0
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Mon, 09 May 2011 13:04:16 +0200
Thatbs how it should work. In your example, <xsl:value-of select="author"/> doesnbt yield a sequence of values (of length > 1) but a single text node. Only if you had a sequence of length > 1 youbd see the separator.

In your example you may process the author element with a dedicated template:

<xsl:template match="author">
  <xsl:if test="first">
    <xsl:value-of select="first" />
    <xsl:text> </xsl:text>
  <xsl:value-of select="last" />

or in a more concise form, using the default separator between the items author/first and author/last:

<xsl:value-of select="author/first,author/last"/>

as you already suggested. In order to render the author name in 'Last, First' form, you may use:

<xsl:value-of select="author/last,author/first" separator=", " />

In order to render a list of authors (comma separation between authors, space separation between first and last), you may use:

<xsl:value-of select="for $a in (book/author) return string-join(($a/first, $a/last), ' ')" separator=", " />

You see, just like in Perl, therebs more than way to do itb&


On 2011-05-09 12:48, Christian Rinderknecht wrote:
Dear list members,

I have a beginner's question about the behaviour of the attribute
"separator" of the element xsl:value-of in XSLT 2.0.

The standard at section 11.4.3 states:

"If the separator attribute is present, then the effective value of
this attribute is used to separate adjacent items in the result
sequence, as described in 5.7.2 Constructing Simple Content. In the
absence of this attribute, the default separator is a single space
(#x20) when the content is specified using the select attribute, or a
zero-length string when the content is specified using a sequence

The Big Book by Michael Kay (4th ed.), page 498--499 says:

"[...] <xsl:value-of select="author"/> [...] all the authors are now
output, using a single space as the default separator."

Let us say that I have a subtree like


Using Saxon HE 9-3-0-4j and assuming the current node is the parent of
author, the result of

<xsl:value-of select="author" separator=" "/>


<xsl:value-of select="author" separator="' '"/>

is the same as

<xsl:value-of select="author"/>

that is, 'PriscillaWalmsley'. But

<xsl:value-of select="author/first,author/last"/>


'Priscilla Walmsley'.

Is this the semantics intended?

Best regards,


PS In case this is not a totally stupid question, here is my complete

book.dtd is

<!ELEMENT book (author, chapter+)>

<!ELEMENT author (first,last)>
<!ELEMENT first (#PCDATA)>

<!ELEMENT chapter (section*)>
<!ATTLIST chapter title CDATA #REQUIRED>

<!ELEMENT section (section*)>
<!ATTLIST section title CDATA #REQUIRED>

num1.xml is

<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE book SYSTEM "book.dtd">

<book title="Definitive XML Schema">

<chapter title="A quick tour of XML Schema">
<section title="An example schema"/>
<section title="The components of XML Schema">
<section title="Declarations vs. definitions"/>
<section title="Global vs. local components"/>
<section title="Elements and attributes">
<section title="The tag/type distinction"/>

<chapter title="Instances and schemas">
<section title="Using the instance attributes"/>
<section title="Schema processing">
<section title="Validation"/>
<section title="Augmenting the instance"/>

<chapter title="Conclusion"/>


num1.xsl is

<?xml version="1.0" encoding="UTF-8"?>

<xsl:transform version="2.0"

<xsl:output method="xhtml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"

<xsl:template match="/">
<xsl:apply-templates select="book"/>

<xsl:template match="book" as="element(xhtml:html)">
<html xmlns=""; xml:lang="en" lang="en">
<title><xsl:value-of select="@title"/></title>
<h2><xsl:value-of select="@title"/></h2>
<p>by <xsl:value-of select="author"/></p>
<h3>Table of contents</h3>
<xsl:apply-templates select="chapter"/>

<xsl:template match="section|chapter" as="element(xhtml:li)">
<li xmlns="";>
<xsl:value-of select="@title"/>
<xsl:if test="not(empty(section))">
<xsl:apply-templates select="section"/>


-- Gerrit Imsieke GeschC$ftsfC<hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx,

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

GeschC$ftsfC<hrer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard VC6ckler

Current Thread