I was going through the book XSLT 2.0 and XPath 2.0 by Michael Kay. I have gone through the topic of white space nodes. In this topic there is one example given.
<person>
<name>Prudence Flowers</name>
<employer>Lloyds Bank</employer>
<place-of-work>
71 Lombard Street
London, UK
<zip>EC3P 3BS</zip>
</place-of-work>
</person>
There are several text nodes present in the above XML.
- Between starting of the
<name>
element and end of the<person>
element. - Starting of the
<name>
and ending of the<employer>
element - Starting of the
<place-of-work>
element and end of the<employer>
element - End of the
<zip>
element and</place-of-work>
. </place-of-work>
element and</person>
element
If the below stylesheet is the stylesheet to transform the XML.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="person"/>
</xsl:stylesheet>
Then my question is that if I execute the above XSLT file the it won't strip the whitespace node between the end of the <zip>
element and </place-of-work>
. Why?
Because the parent of that text node is the
place-of-work
element, not theperson
element, andplace-of-work
is not one of the elements that you have specified asstrip-space
. The whitespace text nodes between<person>
and<name>
and between</name>
and<employer>
are direct children of theperson
element, so they will get stripped.