This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Tree Fragment - How do I test it AND output it?
- From: "Chris Bayes" <chris at bayes dot co dot uk>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 18 Dec 2001 08:27:23 -0000
- Subject: RE: [xsl] Tree Fragment - How do I test it AND output it?
- Reply-to: xsl-list at lists dot mulberrytech dot com
David,
Not sure what you mean (it's early). You can't do both. Well you can but
you can't recurse returning a value to the calling template and output
nodes to the result tree at the same time. Here are a few examples that
show a few things you can do.
<?xml version="1.0" ?>
<values a="3" b="5">
</values>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
extension-element-prefixes="msxsl"
>
<xsl:template match="/values">
<xsl:variable name="resultFromTemplateValue">
<xsl:call-template name="namedTemplateValue"/>
</xsl:variable>
<xsl:variable name="resultFromTemplateRtf">
<xsl:call-template name="namedTemplateRtf"/>
</xsl:variable>
<svg> ... here is some stuff
I actually want to output, because I'm drawing svg.
<g><xsl:value-of
select="$resultFromTemplateValue"/></g>
<g><xsl:value-of select="$resultFromTemplateRtf"/></g>
<g><xsl:call-template name="namedTemplateValue"/></g>
<g><xsl:call-template name="namedTemplateRtf"/></g>
<g>A Result <xsl:value-of
select="msxsl:node-set($resultFromTemplateRtf)/a *
msxsl:node-set($resultFromTemplateRtf)/b"/></g>
</svg>
</xsl:template>
<xsl:template name="namedTemplateValue">
<xsl:variable name="resultFromTemplate">
<!--you would call the template again here-->
<xsl:value-of select="@a * @b" />
</xsl:variable>
<xsl:if test="$resultFromTemplate != 0"><g>[Result !=
0]</g></xsl:if>
<xsl:value-of select="$resultFromTemplate"/>
</xsl:template>
<xsl:template name="namedTemplateRtf">
<xsl:variable name="resultFromTemplate">
<!--you would call the template again here-->
<a><xsl:value-of select="@a" /></a>
<b><xsl:value-of select="@b" /></b>
</xsl:variable>
<xsl:if test="msxsl:node-set($resultFromTemplate)/a *
msxsl:node-set($resultFromTemplate)/b != 0"><g>[Result !=
0]</g></xsl:if>
<xsl:copy-of select="$resultFromTemplate"/>
</xsl:template>
</xsl:stylesheet>
Produces
<?xml version="1.0" encoding="UTF-16" ?>
<svg>
... here is some stuff I actually want to output, because I'm drawing
svg.
<g>[Result != 0]15</g>
<g>[Result != 0]35</g>
<g>
<g>[Result != 0]</g>
15
</g>
<g>
<g>[Result != 0]</g>
<a>3</a>
<b>5</b>
</g>
<g>A Result 15</g>
</svg>
Ciao Chris
XML/XSL Portal
http://www.bayes.co.uk/xml
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of
> David Penton
> Sent: 18 December 2001 05:08
> To: xsl-list@lists.mulberrytech.com
> Subject: [xsl] Tree Fragment - How do I test it AND output it?
>
>
> 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
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list