xsl:strip-space doesn't work properly
Added by Anonymous about 16 years ago
Legacy ID: #5589325 Legacy Poster: Wolfgang Schindler (ponsdv)
The beginning of my XML2XHTML XSLT 2.0 stylesheet looks like this: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xsl xs fn"> <xsl:strip-space elements="*"/> <xsl:output method="xhtml" encoding="UTF-8" indent="no"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> ... The input file has indentations and line-breaks between element tags. The XHTML output has line-breaks and tabs which lead to unwanted whitespace in the rendering. I'm using saxonsa 9. What's wrong with my stylesheet? Cheers Wolfgang
Replies (4)
Please register to reply
RE: xsl:strip-space doesn't work properly - Added by Anonymous about 16 years ago
Legacy ID: #5589385 Legacy Poster: Michael Kay (mhkay)
Please demonstrate the problem by providing a complete (hopefully short) source document and stylesheet, with the actual output and the intended output. The usual problem with xsl:strip-space is imagining it does something different from what it actually does.
RE: xsl:strip-space doesn't work properly - Added by Anonymous about 16 years ago
Legacy ID: #5590013 Legacy Poster: Wolfgang Schindler (ponsdv)
I have drastically simplified the input file and the XSLT to make it more readable for you. My test XML input is: <?xml version="1.0" encoding="UTF-8"?> <dict> <entry> <HW>aalen</HW> <POS>VERB</POS> <SYNTAX>mit sich</SYNTAX> <REGISTER>umg</REGISTER> <DEF>sich behaglich ausstrecken</DEF> <TRANS>to stretch out</TRANS> </entry> </dict> My XSLT looks like this: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xsl xs fn"> <xsl:strip-space elements="*"/> <xsl:output method="xhtml" encoding="UTF-8" indent="no"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="dict"> <html> <head> <title>Test</title> </head> <body class="dict"> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="entry"> <p class="entry"> <xsl:apply-templates/> </p> </xsl:template> <xsl:template match="DEF"> <xsl:text> </xsl:text> <xsl:text>(</xsl:text> <span class="DEF" style="font-style:normal;font-weight:normal"> <xsl:apply-templates/> </span> <xsl:text>)</xsl:text> </xsl:template> <xsl:template match="HW"> <span class="HW" style="font-weight:bold;color:blue;font-size:11pt"> <xsl:apply-templates/> </span> </xsl:template> <xsl:template match="POS"/> <xsl:template match="REGISTER"> <xsl:text> </xsl:text> <span style="font-style:italic"> <xsl:text>(</xsl:text> </span> <span class="REGISTER" style="font-style:italic"> <xsl:apply-templates/> </span> <span style="font-style:italic"> <xsl:text>)</xsl:text> </span> </xsl:template> <xsl:template match="SYNTAX"> <xsl:text> </xsl:text> <span class="SYNTAX" style="font-style:italic"> <xsl:apply-templates/> </span> </xsl:template> <xsl:template match="TRANS"> <xsl:text> </xsl:text> <span class="TRANS"> <xsl:apply-templates/> </span> </xsl:template> </xsl:stylesheet> And the XHTML output is: <?xml version="1.0" encoding="UTF-8"?><html><head><title>Test</title></head><body class="dict"><p><span class="HW" style="font-weight:bold;color:blue;font-size:11pt">aalen</span> <span class="SYNTAX" style="font-style:italic">mit sich </span> <span style="font-style:italic">(</span><span class="REGISTER" style="font-style:italic">umg</span><span style="font-style:italic">)</span> (<span class="DEF" style="font-style:normal;font-weight:normal">sich behaglich ausstrecken</span>) <span class="TRANS">to stretch out </span></p></body></html> In the output there is whitespace within the span element of class "SYNTAX" which wasn't there in the original XML input file and which I didn't add intentionally in the XSLT. I see that xsl:strip-space cannot work as the whitespace is within the element content, but nevertheless the question is: where does it come from or more important: how will I get rid of it? Cheers Wolfgang
RE: xsl:strip-space doesn't work properly - Added by Anonymous about 16 years ago
Legacy ID: #5591541 Legacy Poster: Michael Kay (mhkay)
There are some strange invisible characters in your stylesheet. I don't see them in either the email body or the web page, but when I cut and paste the text from either they appear in my text editor as question marks. They appear for example after the <xsl:apply-templates/> in <xsl:template match="SYNTAX"> <xsl:text> </xsl:text> <span class="SYNTAX" style="font-style:italic"> <xsl:apply-templates/> </span> </xsl:template> xsl:strip-space has no effect on these characters because they are not spaces - I have no idea what they actually are.
RE: xsl:strip-space doesn't work properly - Added by Anonymous about 16 years ago
Legacy ID: #5596899 Legacy Poster: Wolfgang Schindler (ponsdv)
It's still quite strange how I got any of these in my stylesheet. I have profited from your hint in reformatting my original, much more complex stylesheet (the one I pasted here is only a tiny portion) and the problem seems to be gone. Many thanks for your kind assistance!
Please register to reply