This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: looping without changing context node
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] looping without changing context node
- From: Guillaume Rousse <rousse at ccr dot jussieu dot fr>
- Date: Thu, 13 Sep 2001 17:05:00 +0200
- Organization: =?iso8859-1?q?Universit=E9=20Pierre=20&=20Marie?= Curie
- References: <000901c13c63$2f01cac0$fc453c3e@PCUKMKA>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Ainsi parlait Michael Kay :
> > Now, if i want to list successive state of <foo>, i want to call this
> > template for each <modification>, with its position as
> > parameter, for the
> > current context node. But for-each statement change this context node.
> >
> > I also imagined writing a template matching a <modification>
> > node, but then i
> > can't call a named template for another node as the context one.
> >
> > Any idea ?
>
> Pass the value of the context node or position as a parameter to the called
> template, using xsl:with-param.
This doesn't solve the main problem: if i want to use parameters, i have to
use a named template, thus keep the current context node, so i can't use a
for-each statement.
I've used a matching template, this one using count(preceding-siblings)+1 to
obtain his position, using a for-each select matching only its ancestor to
deplace the context node. It's ugly, but it works...
document:
<foo>
<modification id="mod1"/>
<modification id="mod2"/>
<modification id="mod3"/>
</foo>
style:
<!-- display a foo element, using given level of modification -->
<template name="foo-display>
<param name="limit"/>
..
</template>
<!-- standard foo template, using all modifications -->
<template match="foo">
<call-template name="foo-display>
<with param name="limit" select="count(modification)"/>
</call-template>
</template>
<!-- detail foo template, showing all successive modifications -->
<template match="foo" mode="details">
<for-each select="modification">
<apply-template select="."/>
</for-each>
</template>
<!-- specific modification foo template -->
<template match="foo/modification">
<variable name="position" select="count(preceding-sibling)+1"/>
<!-- ugly hack to change context node to parent foo -->
<for-each select="..">
<call-template name="foo-display">
<with-param name="limit" select="$position"/>
</call-template>
</for-each>
</template>
--
Guillaume Rousse <rousse@ccr.jussieu.fr>
GPG key http://lis.snv.jussieu.fr/~rousse/gpgkey.html
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list