[xsl] Effects of white space between xml elements

Subject: [xsl] Effects of white space between xml elements
From: Nat Wilson <beltramie@xxxxxxxxx>
Date: Mon, 23 Feb 2009 16:32:40 -0600
Does white space between elements of an xml document effect the output
of a transformation of that document?  I noticed that sometimes adding
a new line in between the closing tag of one element and the opening
tag of the next element changes my output, even though I am working
with the same stylesheet.

I thought that white space in an XML document was ignored during the
transformation; that the only thing that will effect the output are
the on/off tags and how they are nested in each other.  If tags are
nested properly, shouldn't white space and new lines in between
elements be irrelevant?

Here is an example of what I mean.

Stylesheet element I am using:

    <xsl:template match="HERB/actions">
        <p></p>
        <xsl:text>Effects: </xsl:text>
        <xsl:for-each select="child::node()">
            <xsl:apply-templates/>
            <xsl:text>, </xsl:text>
        </xsl:for-each>
        <xsl:text>.</xsl:text>
    </xsl:template>

2 inputs Im using with this stylesheet, only different in their
spacing between elements:

Input 1:

<chemistry><activeIngredient>Coniine</activeIngredient></chemistry>
    <actions><effect>antispasmodic</effect><effect>sedative</effect><effect>poison
antidote</effect></actions>

Output 1:

 "Effects: antispasmodic, sedative, poison antidote,"

Input 2 (has new lines separating the <effect> elements but nested the same>

<chemistry><activeIngredient>Coniine</activeIngredient></chemistry>
    <actions>
        <effect>antispasmodic</effect>
        <effect>sedative</effect>
        <effect>poison antidote</effect>
    </actions>

Output 2:

"Effects: , antispasmodic, , sedative, , poison antidote, ,"

Why would it add this extra comma in the output list?  Is it that I am
writing the xsl element incorrectly?  Is there some aspect of XML that
I am totally missing?  And if so, are there other times that the
output can be different due to more/less white space between elements?

Thanks,

Nat Wilson
Environment
Transformer Saxon 6.5.5
Run with oXygen 10.0
xml version="1.0" encoding="UTF-8"



-- 
Nat

Current Thread