Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xslt: continue in for-each-group?

Reply
Thread Tools

xslt: continue in for-each-group?

 
 
bbembi_de@lycos.de
Guest
Posts: n/a
 
      02-05-2008
Hello everyone,

I have just a little xslt problem:

<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.

How can I do that?

Thanks very much.

bye bembi
 
Reply With Quote
 
 
 
 
Alain Ketterlin
Guest
Posts: n/a
 
      02-05-2008
"(E-Mail Removed)" <(E-Mail Removed)> writes:

> I have just a little xslt problem:
>
> <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.
>
> How can I do that?


<xsl:choose> ?

-- Alain.
 
Reply With Quote
 
 
 
 
Pavel Lepin
Guest
Posts: n/a
 
      02-05-2008

http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote in
<(E-Mail Removed)>:
> <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.
 
Reply With Quote
 
bbembi_de@lycos.de
Guest
Posts: n/a
 
      02-06-2008
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 <(E-Mail Removed)> wrote:
> (E-Mail Removed) <(E-Mail Removed)> wrote in
> <(E-Mail Removed)>:
>
> > <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.


 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-07-2008
I presume you've already looked at all the grouping techniques in

http://www.dpawson.co.uk/xsl/sect2/N4486.html
http://www.dpawson.co.uk/xsl/sect2/N6280.html

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      02-07-2008
(E-Mail Removed) wrote:
> 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.


I am not sure I understand what you want to achieve, your sample has
just one item element having two subitem children with an attribute
named 'name' which has different values so there is not much to group
by. And your XPath does group-by="name", if you want to group on the
attribute you need group-by="@name".
Can you show us enough XML sample data that it becomes clear what you
want to group?

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
bbembi_de@lycos.de
Guest
Posts: n/a
 
      02-11-2008
Hello again,

given the following xml:
<root>
<item name="111">
<subitem name="aaa">
<subitem name="bbb">
<subitem name="ccc">
</item>
<item name="222">
<subitem name="ccc">
<subitem name="bbb">
</item>

If i want all item names that have the subitems aaa and ccc I want the
output:
111

but currently I get the output:
111
111

How can I do this?

thanks bembi




On 7 Feb., 17:12, Martin Honnen <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > Thanks very much for the info.

>
> > Now I found out what my real problem is (I triedxsl: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.

>
> I am not sure I understand what you want to achieve, your sample has
> just one item element having two subitem children with an attribute
> named 'name' which has different values so there is not much to group
> by. And your XPath does group-by="name", if you want to group on the
> attribute you need group-by="@name".
> Can you show us enough XML sample data that it becomes clear what you
> want to group?
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/


 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-11-2008
You haven't shown your code, but this sounds like a simple matter of
rewriting the test...

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
uCertify's 50% discount will continue Kennedy_f MCSE 0 03-31-2005 10:09 AM
Continue previous session in Firefox? Cueball Firefox 7 03-25-2005 02:48 AM
Unity VPN client 4.6.00.0045 - DNS Troubles continue Eric Sorenson Cisco 1 01-24-2005 10:44 PM
ASP to continue processing. Sam ASP .Net 7 09-25-2004 05:12 AM
MN-700 Disconnects continue after Firmware upgrade JR Wireless Networking 0 08-24-2004 03:09 PM



Advertisments