Re: [xsl] looping problem, <xsl: for-each>??

Subject: Re: [xsl] looping problem, <xsl: for-each>??
From: Mukul Gandhi <mukulgw3@xxxxxxxxx>
Date: Tue, 7 Oct 2003 10:08:06 -0700 (PDT)
Hi James,
 This is a grouping problem, which can be solved by
the Muenchian method. Please try the following XSL --

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
   <xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
   <xsl:key name="x" match="/rss/channel/item"
use="category" />
   
    <xsl:template match="/">
      <xsl:for-each select="rss/channel/item">
	<xsl:if test="generate-id(.) = generate-id(key('x',
category)[1])"> 
         <h1>
            <xsl:value-of select="category" />
         </h1>             
	 <xsl:for-each select="key('x', category)">	  
ITEM<!-- ?? -->  <xsl:value-of select="description"/>
	 </xsl:for-each>
       </xsl:if>
     </xsl:for-each>
   </xsl:template>

</xsl:stylesheet>

You want the labels to be output as -- ITEM1, ITEM2,
ITEM3, ITEM 4. I cannot think of a good way to do
this. <!-- ?? --> part of my XSL needs to be
completed.

Something using position() and count() should be
required..

As I requested earlier also on the list --
If there is a feature to increment a variable (not the
present xsl:variable! , as it operates on many things
like tree fragments etc.) , it would be convenient to
perform just the same thing as required here.. 

But its very difficult to introduce the variable
incrementing in XSLT, as it would radically change the
nature of XSLT processing. 

Is something thought of *to fulfill this kind of
requirement* ? 

Regards,
Mukul


--- james walker <jameswalkerandy@xxxxxxxxxxx> wrote:
> Hi,
> I have the following format but am having trouble
> trying to group items (in 
> html) under one common category so that it isnt
> repeated for every item but 
> can act as a title:
> <rss version="0.92">
> - <channel>
> - <item>
>   <title>title here</title>
>   <category>Top Stories</category>
>   <link>http</link>
>   <description>text is heredescription>
>   </item>
> </channel>
> <item>
>   <title>title here</title>
>   <category>top stories</category>
>   <link>http</link>
>   <description>text is heredescription>
>   </item>
> </channel>
> <item>
>   <title>title here</title>
>   <category>Stories today</category>
>   <link>http</link>
>   <description>text is heredescription>
>   </item>
> </channel>
> <item>
>   <title>title here</title>
>   <category>Stories today</category>
>   <link>http</link>
>   <description>text is heredescription>
>   </item>
> </channel>
> </rss>
> 
> e.g. the final look i wanted to create was:
> <h1>top stories </h1>
> ITEM1 <xsl:value-of select="description">
> ITEM2 <xsl:value-of select="description">
> <h1>stories today</h1>
> ITEM3 <xsl:value-of select="description">
> ITEM4 <xsl:value-of select="description">
> 
> but wasn't sure whetehr i should use count or
> for-each fucntion to gather 
> common category title for several items.....
> 
>
_________________________________________________________________
> Find a cheaper internet access deal - choose one to
> suit you. 
> http://www.msn.co.uk/internetaccess
> 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread