[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Tree Fragment - How do I test it AND output it?


Subject: [xsl] Tree Fragment - How do I test it AND output it?
From: "David Penton" <dpenton@xxxxxxxxxxxxx>
Date: Tue, 18 Dec 2001 00:08:17 -0500

How do I both test the "return" value from a template, and output some of
the result nodes?  I have written a recursive template that is intended to
"draw" some xml as svg.  The template must do some calculations about the
depth of the input xml, and about its "width" (i.e. how many children a
particular node has.  My problem is that I do not know how to both get a
"return" value from a template that I can test (i.e. treating the named
template like a kind of function), and also get output from it:

Roughly, I want to do this:

<xsl:template name="namedTemplate">
    <svg> ... here is some stuff
         I actually want to output, because I'm drawing svg.
    </svg>

   <!--
        but I need to compute a value via a recursive call
        to this same template:
    -->

        <xsl:variable name="resultFromTemplate">
            <xsl:call-template name="namedTemplate">
        </xsl:variable>

        <!-- and use the "returned" value: -->

        <xsl:if test="$resultFromTemplate != 0"> ...</xsl:if>

   <!--
        Here I'll "return" a value computed in this
        named template, to control processing in the calling
        template (i.e. the earlier instance of this same one):
    -->

    <xsl:value-of select="$somethingCalculatedHere"/>

</xsl:template>


Is there a way to do this?  I suppose, to get at the results, I shall have
to convert to a nodelist.  But I don't really see how to both use the tree
as a return value, and also to output it.

Does this make sense?

- Dave Penton -


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



Current Thread
Keywords
xml