Subject: Re: [xsl] looping without changing context node From: Guillaume Rousse <rousse@xxxxxxxxxxxxxx> Date: Thu, 13 Sep 2001 17:05:00 +0200 |
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@xxxxxxxxxxxxxx> GPG key http://lis.snv.jussieu.fr/~rousse/gpgkey.html XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] looping without changing , Michael Kay | Thread | Re: [xsl] looping without changing , David Carlisle |
RE: [xsl] Xpath newbie question, Michael Kay | Date | RE: [xsl] outputing elements correc, Auguste Oumar |
Month |