1

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?

Eero Helenius
  • 2,584
  • 21
  • 22
Beast
  • 639
  • 2
  • 14
  • 29

1 Answers1

0

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.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
  • In that case If I specify then it must remove that text node as well Am I right? – Beast Mar 06 '13 at 12:08
  • @Beast yes, `` will tell it to remove _all_ whitespace-only text nodes in the whole document (unless countermanded by a more specific `xsl:preserve-space`). – Ian Roberts Mar 06 '13 at 12:33
  • Thanks actually I misunderstood the statement mentioned in the book. Thanks for the clarification budy. – Beast Mar 06 '13 at 13:01