This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: preserve-space and strip-space?


----- Original Message -----
From: "Zwetselaar M. van (Marco)" <Marco.van.Zwetselaar@nl.fortis.com>
To: <xsl-list@lists.mulberrytech.com>
Sent: Monday, September 17, 2001 9:16 AM
Subject: RE: [xsl] preserve-space and strip-space?


> Whitespace-stripping (see XSLT Spec section 3.4) is not about stripping
any
> whitespace, it is about stripping text nodes that contain only whitespace.

I had seen it, but it was around 1:00 in the morning last night when I was
going over it (a little tired today :) )

For the record, I had tried it using the content of spaces, and was getting
the same problem.  This is using the .NET framework classes.  When I tested
using the msxsl command line utility this morning (after the responses), it
worked.  So, now I'm off chasing a .NET issue.

The spec does not say that the value of the text node containing spaces is
preserved, it only mentions that the text node itself is preserved.  This
seems to be consistent with the interpretation of both version 3.1 and 4 of
MSXML:  the node is preserved, but only 1 space of n spaces is preserved.
Is this correct, or is there a way to preserve all of the spaces for an
element?

For anyone interested, given the stylesheet:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:output method="xml" version="1.0" />
 <xsl:strip-space elements="link" />
 <xsl:template match="/">
  <xsl:for-each select="links/link">
   <xsl:text>[</xsl:text>
   <xsl:value-of select="." />
   <xsl:text>]</xsl:text>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

And the source document

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

Running source code in .NET:

    Sub Main()
        Dim trans As System.Xml.Xsl.XslTransform = New
System.Xml.Xsl.XslTransform()

        Try
            trans.Load("c:\test\trans.xslt")
            trans.Transform("c:\test\source.xml", "c:\test\outfile.xml")
        Catch errOops As Exception
            System.Diagnostics.Debug.WriteLine(errOops.ToString)
        End Try
    End Sub


Yields the output (no spaces):

<?xml version="1.0" encoding="utf-8"?>[]


Running VB6 code:

Option Explicit

Private Sub Command1_Click()
    Dim xml As New MSXML2.DOMDocument40
    Dim trans As New MSXML2.DOMDocument40
    Dim fso As New Scripting.FileSystemObject
    Dim strm As Scripting.TextStream

    On Error GoTo eh

    xml.Load "c:\test\source.xml"
    'xml.preserveWhiteSpace = True

    trans.Load "c:\test\trans.xslt"

    Set strm = fso.OpenTextFile("c:\test\outfile.xml", ForWriting, True)
    strm.Write xml.transformNode(trans)
    strm.Close
    Set xml = Nothing
    Set trans = Nothing
    Exit Sub
eh:
    Debug.Assert False
    strm.Close
    Set strm = Nothing
    Set fso = Nothing
    Set trans = Nothing
    Set xml = Nothing
End Sub

yields the following result (only 1 space of the 5 in the source document):

<?xml version="1.0" encoding="UTF-16"?>[ ]




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]