xsl-list
[Top] [All Lists]

Re: Passing document fragments as nodsets

2003-07-07 03:56:38
Hi Simon,

This is the test that fails every time, but I know the node set
contains one node. Is the test correct for erroring if the set is
null?

<xsl:if test="not($text-nodes)">
    <xsl:message terminate="yes">
        Template footer-text-rows was called without
        a value passed in text-nodes. Check the code!
    </xsl:message>
</xsl:if>

That's the correct test for seeing if $text-nodes is empty or not; you
should get the error message if $text-nodes is empty.

When footer-text-rows is called with:

      <xsl:if test="$text-node-count &gt; 0">
        <xsl:call-template name="footer-text-rows">
          <xsl:with-param name="node-set" select="$text-nodes" />
        </xsl:call-template>
      </xsl:if>

then $text-nodes will always be empty, since you're only passing in a
value for the $node-set parameter and the $text-nodes parameter
defaults to the empty node set.

When you call it in:

  <!-- Center footer section: table generating template -->
  <xsl:template name="footer-center">
    <xsl:param name="text-nodes" select="/.." />

    <table>
      <xsl:call-template name="footer-text-rows">
        <xsl:with-param name="text-nodes" select="$text-nodes" />
      </xsl:call-template>
    </table>
  </xsl:template>

then the value of $text-nodes depends on the value of $text-nodes in
the footer-center template, which depends on what:

          <xsl:call-template name="footer-center">
            <xsl:with-param name="text-nodes">
              <xsl:value-of select="xalan:nodeset(.)/text[(_at_)position =
'center']" />
            </xsl:with-param>
          </xsl:call-template>

is doing; since I don't have the source document I can't tell whether
$text-nodes will actually hold anything here.

By the way, I doubt that your "counter" template is doing what you
want it to do, since the test:

  $node-set[$count] = last()

is true if the string value of the node in $node-set at the position
of $count is equal to the number of nodes currently being processed,
which is probably always going to be 1, assuming that your XML
document looks like:

<?xml version="1.0"?>
<footer>
  ...
</footer>

If you want to count how many nodes are in a node set, you should use
the count() function:

  count($node-set)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list