GNOME Bugzilla – Bug 636536
text() XPath expression in <xsl:if> from xsltproc select text of all subnodes.
Last modified: 2012-11-03 15:36:32 UTC
In following example condition <xsl:if test="text()"> MUST evaluate to false. $ cat my.xml <?xml version="1.0"?> <test> <x a="1"> <x a="2" b="B"> <x> <y>y31</y> <y>y32</y> </x> </x> </x> </test> $ cat my.xsl <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" omit-xml-declaration="no" indent="yes"/> <xsl:template match="text()"/> <xsl:template match="/"> <xsl:apply-templates select="/test"> </xsl:apply-templates> </xsl:template> <xsl:template match="test"> <xsl:if test="text()"> <XXX> <xsl:value-of select="."/> </XXX> </xsl:if> </xsl:template> </xsl:stylesheet> $ xsltproc -v my.xsl my.xml >my.out creating dictionary for stylesheet reusing dictionary from my.xsl for stylesheet xsltParseStylesheetProcess : found stylesheet xsltPrecomputeStylesheet: removing ignorable blank node xsltCompilePattern : parsing 'text()' xsltCompilePattern : parsed text(), default priority -0.500000 added pattern : 'text()' priority -0.500000 xsltCompilePattern : parsing '/' xsltCompilePattern : parsed /, default priority 0.500000 added pattern : '/' priority 0.500000 xsltCompilePattern : parsing 'test' xsltCompilePattern : parsed test, default priority 0.000000 added pattern : 'test' priority 0.000000 parsed 3 templates Resolving attribute sets references Creating sub-dictionary from stylesheet for transformation Registered 0 modules reusing transformation dict for output Registering global variables Registering global variables from my.xsl xsltProcessOneNode: applying template '/' for / xsltApplyTemplates: select /test xsltApplyTemplates: list of 1 nodes xsltProcessOneNode: applying template 'test' for test xsltIf: test text() xsltIf: test evaluate to 1 xsltApplySequenceConstructor: copy node XXX xsltValueOf: select . xsltCopyTextString: copy text y31 y32 xsltValueOf: result ' y31 y32 ' freeing transformation dictionary freeing dictionary from stylesheet $ cat my.out <?xml version="1.0"?> <XXX> y31 y32 </XXX>
This is not a bug. For source documents, every element is whitespace-preserving by default. If you want to strip the two whitespace text nodes of the "test" element, use: <xsl:strip-space elements="test"/>