Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: xslt: continue in for-each-group? >Thread Next - Re: xslt: continue in for-each-group? Re: xslt: continue in for-each-group?To: NULL Date: 2/5/2008 11:36:00 PM Thanks very much for the info.
Now I found out what my real problem is (I tried xsl:choose before
writing the first mail):
I have a xml like this:
<root>
<item name="111">
<subitem name="aaa">
<subitem name="bbb">
</item>....
I group the subitems but only want to output a item name once.
I want only one item output.
<xsl:for-each-group select="subitem" group-by="name">
<xsl:apply-templates select="current-group()" //here I output
the name of the parent (item) but this should be only once for every
item.
bye bembi
On 5 Feb., 13:10, Pavel Lepin <p.le...@ctncorp.com> wrote:
> bbembi...@lycos.de <bbembi...@lycos.de> wrote in
> <8ba82eb2-d6b9-42db-bace-0b9bd5664...@d21g2000prf.googlegroups.com>:
>
> > <xsl:for-each-group select="item" group-by="name">
> > <xsl:if test="contains(name, 'teststring11')">
> > <xsl:apply-templates select="current-group()"/>
> > </xsl:if>
> > <xsl:if test="contains(name, 'teststring22')">
> > <xsl:apply-templates select="current-group()"/>
> > </xsl:if>
> > </xsl:for-each-group>
>
> > This xslt is fine, but has 1 problem: I want to make a
> > "continue" in my if clauses. If the program walks into a
> > if clause it should go to the next for-each-group. I don't
> > want every if clause to be executed, only one.
>
> While <xsl:choose/> is clearly an option, you might want to
> consider the fact that specifying templates matching your
> groups is often a better option. Your example seems to be
> equivalent to:
>
> <xsl:for-each-group select="item" group-by="name">
> <xsl:apply-templates select="current-group()"/>
> </xsl:for-each-group>
>
> ...but assuming you meant something like:
>
> <xsl:for-each-group select="item" group-by="name">
> <xsl:if test="contains(name,'teststring11')">
> <xsl:apply-templates select="current-group()"
> mode="mode-11"/>
> </xsl:if>
> <xsl:if test="contains(name,'teststring22')">
> <xsl:apply-templates select="current-group()"
> mode="mode-22"/>
> </xsl:if>
> </xsl:for-each-group>
>
> ...you might redesign that using just one template
> application and properly matching templates, such as:
>
> <xsl:template match="item[contains(name,'teststring11')]>
> <Stuff-11/>
> </xsl:template>
> <xsl:template match="item[contains(name,'teststring22')]>
> <Stuff-22/>
> </xsl:template>
>
> --
> When all you have is a transformation engine, everything
> looks like a tree.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
