This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: looping without changing context node


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]