xsl-list
[Top] [All Lists]

Re: [xsl] Effects of white space between xml elements

2009-03-06 01:09:28
Thanks a lot for all your suggestions.  If I am interpreting what you
all are saying right, white space is handled differently depending on
a few factors. 1) the transformer can follow different rules 2) the
stylesheet can have rules that tell the transformer specifically how
and when to handle white space.

Ill try some of these rules out and see what the results are, thanks
for the help everyone.

Nat

On Mon, Feb 23, 2009 at 4:32 PM, Nat Wilson <beltramie(_at_)gmail(_dot_)com> 
wrote:
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




-- 
Nat

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>