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

Re: Recursion Examples

Subject: Re: Recursion Examples
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 1 May 2001 08:02:16 +0100
xslt recursive example
Hi Larry,

> I wasn't certain if xsl:attribute could take something that fancy
> otherwise, as I've not done that particular trick before. As I said,
> I wasn't 100% certain on the syntax, it may not be necessary. :-)

It's a real kindness not to guess syntax when you're replying to
people's questions, and often one to try out your solution before you
post it.  If you'd have tried yours:

>> <xsl:template match="module">
>>     <ul>
>>         <li>
>>             <xsl:value-of select="name" />
>>             <xsl:apply-templates>
>>                 <xsl:attribute name="select">
>>                     <xsl:text>../module[@parentid='</xsl:text><xsl:value-of
>> select="id" /><xsl:text>']</xsl:text>
>>                 </xsl:attribute>
>>             </xsl:apply-templates>
>>         </li>
>>     </ul>
>> </xsl:template>

you should have found that the XSLT processor objects to you using an
xsl:attribute element within an xsl:apply-templates.  xsl:attribute is
for adding attributes to elements *in the result tree*, not to XSLT
elements.  You can never use xsl:attribute to add an attribute to an
XSLT instruction.

I can see what you're trying to do here though - you're trying to
construct an XPath that uses, within the predicate, the id of the
*current* module element (i.e. the one you're matching in the
template) rather than the id of the *context* module
element (i.e. the one that you're searching for).

There are two ways of doing that.  The simple one is to create a
variable to hold the id of the current module element, and then use
that variable value:

   <xsl:variable name="id" select="id" />
   <xsl:apply-templates select="../module[@parentid = $id]" />

The second is to use the current() function to get the current node
(the module element that you're matching in the template), and get its
id from there:

   <xsl:apply-templates
         select="../module[@parentid = current()/id]" />

I hope that helps clear things up for you,

Jeni

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



 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.