|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Recursion Examples
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








