strip-space removes non-ignorable whitespace
Added by Roberto Pasello about 8 years ago
Using Saxon-PE 9.6 identity xsl transformation which just replaces namespace and works fine. Now I also want to remove all ignorable whitespace from the input document. In other words, remove pretty print if present, without altering anything else.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="xml" omit-xml-declaration="no" indent="no" /> <xsl:strip-space elements="" /> <xsl:template match=""> <xsl:element name="{name()}" namespace="http://xml.output.com/OUTPUT"> <xsl:apply-templates select="node()|@" /> </xsl:element> </xsl:template> <xsl:template match="@"> <xsl:copy-of select="." /> </xsl:template> </xsl:stylesheet>
Input example:
Actual output:
Expected output (freetext content preserved):
</freeText></testData>
In this post it was indicated the correct expectation is the one I outlined above. http://stackoverflow.com/questions/14050522/xslstrip-space-is-not-removing-the-carriage-return Granted I am not using schema-aware as it is only available in Saxon-EE. Is there a way to control this behavior in Saxon-PE? Thanks.
Replies (1)
RE: strip-space removes non-ignorable whitespace - Added by Michael Kay about 8 years ago
The usual definition of "ignorable" whitespace is "whitespace text node children of elements having an element-only content model". That definition only makes sense if you know the content model, that is, if you have a DTD or schema. You can do it with xsl:strip-space, of course, if you enumerate the elements that fit into this category.
I'm afraid that without a DTD or schema, or an explicit list of element names, stripping whitespace selectively really isn't possible.
Please register to reply