Beast
Beast

Reputation: 629

Whitespace node in XSLT

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.

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?

Upvotes: 1

Views: 563

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122364

Then my question is that If I execute the above XSLT file the it wont strip the white space node between theEnd of the Zip element and </place-of-work>. why?

Because the parent of that text node is the place-of-work element, not the person element, and place-of-work is not one of the elements that you have specified as strip-space. The whitespace text nodes between <person> and <name> and between </name> and <employer> are direct children of the person element, so they will get stripped.

Upvotes: 0

Related Questions