[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Help calling templates with parameters

Subject: Re: Help calling templates with parameters
From: "Anton Triest" <anton@xxxxxxxx>
Date: Wed, 22 Sep 2004 09:08:54 +0200
cannot use result tree fragment
Charlie Consumer wrote:
> 
> I'm trying to refactor my XSL so that I can make a
> call to a template from several locations in my XSL. 
> However, I need to parameterize this template with a
> node set of where the data should come from.  I have
> two documents that I'm merging together to result in
> one document. I'm assigning parameter to a XPath to
> the node set which is correct before I call the
> template.  But, when I use it inside the template I
> get "Cannot use result tree fragment.  Error in XPath
> expression, Cannot use result tree fragment."  Here is
> an example of what I'm doing:
> 
> <xsl:for-each select="document($ruleFile)/rulelist/rule[@A='blah']">
>    <xsl:call-template name="insertRule">
>      <xsl:with-param name="currentRule">
>        <xsl:value-of select="current()"/>
>      </xsl:with-param>
>    </xsl:call-template>
> </xsl:for-each>

Hi Charlie,

<xsl:value-of select="current()"/> returns the text contents of
the current element, not the element itself. You can rewrite
the xsl:with-param like this:

<xsl:with-param name="currentRule" select="current()"/>

which has a totally different result, because here, you pass a
pointer to the 'real' current element. Your next template
should work, then.

But altogether, you can do it easily without any params (and much shorter),
by using apply-templates and match: 

  <xsl:variable name="rules" select="document($ruleFile)/rulelist/rule"/>

  <xsl:template match="/">
    <xsl:apply-templates select="$rules[@A='blah']"/>
  </xsl:template>

  <xsl:template match="rule">
    <rule id="{blah/@id}"/>
  </xsl:template>


Cheers,
Anton

 
> <xsl:template name="insertRule">
>    <xsl:param name="currentRule"
>    <xsl:element name="rule">
>       <xsl:attribute name="id">
>         <xsl:value-of select="$currentRule/blah/@id"/>
>         </xsl:attribute>
>    </xsl:element>
> </xsl:template>
>
> I'm using XMLSpy's debugger to step through the XSL,
> and once I enter the template the parameter isn't a
> node set like it was before I called the template, but
> a node fragment.  I don't know what a node fragment
> is.  Can anyone explain this?  And, what am I doing
> wrong here?  Sorry I'm new to XSL.  I tried reading
> the faq and archive, but I couldn't find anything
> about this in either location.
> 
> Charlie

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.