This solution works correctly, thank you.
It strips leading and trailing whitespace.

But now, I am wondering if there is a solution just using libxml2 (without 
libxslt).
In fact, I am requesting for a transformation of the XML document.
Indeed, the original node contains whitespaces and I want to remove them...
So I think the answer is "NO!", because this is the job of stylesheets to apply 
this transformation.

Can someone tell me if there is a way to apply a function which does this work 
in libxml2 ?

----- Mail original -----
De: "Michael Ludwig" <mil...@gmx.de>
À: xml@gnome.org
Envoyé: Mardi 14 Février 2012 21:13:19
Objet: Re: [xml] Remove whitespaces from text nodes

spam.spam.spam.s...@free.fr schrieb am 14.02.2012 um 10:59 (+0100):

> I write a C program using the libxml2 library.

> I would like to have this output (without editing my XML file) :
> "My book "A""
> "My book "B""
> "My book "C""
> 
> The useless whitespaces are removed from text nodes.
> 
> Is there a function which do this work?

Don't know the C API, but in XSLT there's the function normalize-space()
and it does just what you want, so you might want to take a look at the
source of LibXSLT. Or use XSLT directly.


<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

        <xsl:template match="text()" priority="2">
                <xsl:copy-of select="normalize-space()"/>
        </xsl:template>

        <xsl:template match="@*|node()">
                <xsl:copy>
                        <xsl:apply-templates select="@*|node()"/>
                </xsl:copy>
        </xsl:template>

</xsl:stylesheet>

-- 
Michael Ludwig
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
http://mail.gnome.org/mailman/listinfo/xml
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to