Subject: Re: [xsl] Recursion Examples From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Tue, 1 May 2001 08:02:16 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Recursion Examples, Larry Garfield | Thread | Re: [xsl] Recursion Examples, Dan Diebolt |
Re: [xsl] Recursion Examples, Larry Garfield | Date | Re: [xsl] Recursion Examples, Jeni Tennison |
Month |