xsl-list
[Top] [All Lists]

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

2009-02-23 18:17:02
<xsl:for-each select="child::*"> does what you want.

"child::node()" matches the (white space) text nodes in addition.


Mit besten Grüßen / Best wishes,

Hermann Stamm-Wilbrandt
Developer, XML Compiler
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschäftsführung: Erich Baier
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


                                                                       
             Nat Wilson                                                
             <beltramie(_at_)gmail(_dot_)                                       
  
             com>                                                       To
                                       
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
             02/23/2009 11:32                                           cc
             PM                                                        
                                                                   Subject
                                       [xsl] Effects of white space    
             Please respond to         between xml elements            
             xsl-list(_at_)lists(_dot_)mu                                       
  
              lberrytech.com                                           
                                                                       
                                                                       
                                                                       
                                                                       




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

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




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