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

Re: Using xsl:apply-templates with xsl:with-param

Subject: Re: Using xsl:apply-templates with xsl:with-param
From: "Steve Muench" <smuench@xxxxxxxxxxxxx>
Date: Mon, 15 May 2000 13:50:41 -0700
xsl apply templates param
| How is xsl:with-param supposed to work from within an xsl:apply-templates
| element?  The recommendation doesn't seem to actually spell it out, other
| that saying it is allowed.  Consider the following:

I think what's happening here is that your:

    <xsl:template match="/">
        <root>
            <xsl:apply-templates>
                <xsl:with-param name="param">List</xsl:with-param>
            </xsl:apply-templates>
        </root>
    </xsl:template>

tells the XSLT processor to "apply templates" to all children
of the current node (in this case, the root "/"), passing
a parameter.

In your source document, the first child of the root
is the <doc> document element, which you don't have
a specific template to handle. So, this is getting
processed by the built-in template that matches child
elements. It's *this* template that gets the parameter
passed to it, but does nothing with it.

As an education example, try adding the template:

    <xsl:template match="doc">
      <xsl:param name="param">Unset</xsl:param>
      <doc param="{$param}">
        <xsl:apply-templates/>
      </doc>
    </xsl:template>

To you stylesheet, and you'll see that the resulting document
comes out as:

<root>
   <doc param="List">
      <chap title="The beginning" cat="Unset"/>
   </doc>
</root>

showing that the parameter *does* get successfully passed to
the "doc" template, but not recursively on down to the "chapter"
template. You could do one of two things, either change
your initial:

            <xsl:apply-templates>
                <xsl:with-param name="param">List</xsl:with-param>
            </xsl:apply-templates>

To specifically select chapters...

            <xsl:apply-templates select="doc/chapter">
                <xsl:with-param name="param">List</xsl:with-param>
            </xsl:apply-templates>

or, add the "doc" template above that passes the parameter "on down"
the line to the chapter template like this:

    <xsl:template match="doc">
      <xsl:param name="param">Unset</xsl:param>
       <xsl:apply-templates>
         <xsl:with-param name="param" select="$param"/>
       </xsl:apply-templates>
    </xsl:template>

______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
Business Components for Java & XSQL Servlet Development Teams
Oracle Rep to the W3C XSL Working Group



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


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.