After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 636536 - text() XPath expression in <xsl:if> from xsltproc select text of all subnodes.
text() XPath expression in <xsl:if> from xsltproc select text of all subnodes.
Status: RESOLVED NOTABUG
Product: libxslt
Classification: Platform
Component: general
1.1.26
Other Cygwin
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2010-12-05 20:58 UTC by Oleksandr Gavenko
Modified: 2012-11-03 15:36 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Oleksandr Gavenko 2010-12-05 20:58:28 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>
Comment 1 Nick Wellnhofer 2012-08-19 13:20:55 UTC
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"/>