Ignorable whitespace and XSLT
Browsing the "Result still indented despite indent="no"" thread and stumbling just today about that very msxml white space stripping issue, I wondered about the following test case involving ignorable whitespace. I consider "ignorable whitespace" whitespace that can safely be ignored as pretty-printing artefacts by reading the XML document's associated DTD and verifying that the element at hand has not a mixed content model, i.e. it may not contain PCDATA content. I also assume that an underlying XML parser will build a DOM (or deliver SAX events) that correctly identifies ignorable whitespace elements (which it can when reading the associated DTD). Here are my test files: --simple.dtd-- <!ELEMENT root (leaf)*> <!ELEMENT leaf (#PCDATA)> -------------- --test.xml-- <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE root SYSTEM "file:///Users/chris/Desktop/igwstest/simple.dtd"> <root> <leaf>One</leaf> <leaf>Two</leaf> </root> ------------ --test.xsl-- <?xml version='1.0' encoding='iso-8859-1'?> <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/ Transform'> <xsl:output method='xml' encoding='iso-8859-1' indent='no'/> <xsl:template match="root"> <output><xsl:value-of select="child::node()"/></output> </xsl:template> </xsl:stylesheet> ------------ The result is using Saxon 8.1 with an underlying Xerces parser: --result.out-- <?xml version="1.0" encoding="iso-8859-1"?><output> </output> -------------- Note that the ignorable whitespace node between the opening tag <root> and the opening tag <leaf> is considered a significant node in XSLT processing - it is still there. Is this intended behaviour, and if so, why? It makes sense to me to be able to declare elements with <xsl:strip- space> for those cases where there is no DTD on the source XML document and therefore no way for the parser to detect an ignorable whitespace node. In this case, the XSLT author can then use this meachnism to provide that info to XSLT processor "manually". But why is there the need to specify this explicitly for XML documents that come with a DTD? Regards, Christian.
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format