[xslt] XML_DOCUMENT_NODE and boolean testing



If I call a template that doesn't return anything, should
the result (when type converted to boolean) be false?

I call a template and assign the returned RTF to a variable.  If I
test this variable, it's always true, even if the contents are
empty.  The same behavior when I use ext:node-set() to turn the RTF
into a node-set.

Looks like the variable gets a node set with one member, a "fake
node libxslt" with type set to XML_DOCUMENT_NODE.  This node
has no children.  If I pass the variable to an extension function,
I see this:

(gdb) p *item->nodesetval[0].nodeTab[0]         
$8 = {_private = 0x0, type = XML_DOCUMENT_NODE, 
  name = 0x80e1a40 " fake node libxslt", children = 0x0, last = 0x0, 
  parent = 0x0, next = 0x0, prev = 0x0, doc = 0x80a8e80, ns = 0xffffffff, 
  content = 0xffffffff <Address 0xffffffff out of bounds>, properties = 0x0, 
  nsDef = 0x0, psvi = 0x0, line = 19184, extra = 2059}

A script that shows the issue is appended.  The results are:

<?xml version="1.0"?>
<top xmlns:ext="http://xmlsoft.org/XSLT/namespace";>
<rtf>$f is true</rtf>
<rtf>$t is true</rtf>
<node-set>$nf is true</node-set>
<node-set>$nt is true</node-set>
</top>

Thanks,
 Phil


<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:ext="http://xmlsoft.org/XSLT/namespace";>

  <!-- make-stuff returns stuff if the parameter 'value' is true -->
  <xsl:template name="make-stuff">
    <xsl:param name="value"/>
    <xsl:if test="$value">
      <stuff/>
    </xsl:if>
  </xsl:template>

  <xsl:template match="/">
    <top>

      <xsl:variable name="t">
        <xsl:call-template name="make-stuff">
          <xsl:with-param name="value" select="true"/>
        </xsl:call-template>
      </xsl:variable>

      <xsl:variable name="f">
        <xsl:call-template name="make-stuff">
          <xsl:with-param name="value" select="false"/>
        </xsl:call-template>
      </xsl:variable>

      <xsl:if test="$f">
        <rtf>$f is true</rtf>
      </xsl:if>

      <xsl:if test="$t">
        <rtf>$t is true</rtf>
      </xsl:if>

      <xsl:variable name="nt" select="ext:node-set($t)"/>
      <xsl:variable name="nf" select="ext:node-set($f)"/>

      <xsl:if test="$nf">
        <node-set>$nf is true</node-set>
      </xsl:if>

      <xsl:if test="$nt">
        <node-set>$nt is true</node-set>
      </xsl:if>

    </top>
  </xsl:template>

</xsl:stylesheet>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]