A parser reports every whitespace character to the application, indentation included. xml:space states the document's wish: preserve marks whitespace in the element and its descendants as significant, default leaves it to the application. It is only a signal, honored where a tool chooses to. XSLT does: <xsl:strip-space elements="*"/> removes whitespace-only text nodes except under xml:space="preserve", while plain XPath strips nothing:
cat > labels.xml <<'EOF'
<labels>
<label xml:space="preserve"> <b>COOKING</b> <i>aisle 4</i> </label>
<label> <b>TRAVEL</b> <i>aisle 2</i> </label>
</labels>
EOF
cat > strip.xsl <<'EOF'
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="//label">[<xsl:value-of select="."/>] </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
EOF
xslt3 -s:labels.xml -xsl:strip.xsl
xquery -s:labels.xml -qs:'//label ! ("[" || . || "]")'Output
[ COOKING aisle 4 ] [TRAVELaisle 2] "[ COOKING aisle 4 ]" "[ TRAVEL aisle 2 ]"
Stripping fused "TRAVEL" and "aisle", the classic hazard with mixed content. For data fields, keep everything at parse time and clean values explicitly with normalize-space() (String Functions); XSD's whiteSpace facet does the same for typed values (Simple Types and Facets).
xml space
This special attribute can be assigned a value of 'preserve' or 'default'. 'preserve' indicates that white space is to be preserved. 'default' tells the XML processor to use its own scheme to handle white space.<?xml version="1.0" encoding="UTF-8"?>
<title xml:lang="en" xml:space="preserve">Harry Potter</title>