xsl-list
[Top] [All Lists]

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

2003-10-07 18:12:37
Hi Wendell,
 The syntax <xsl:value-of
select="count(preceding::item[category=current()/category])+1"/>
when placed at <!-- ?? --> in my XSL, produces
numbering 1,2,1,2 and not 1,2,3,4 !

I am also interested to know how the numbering
(1,2,3,4 ..) can be produced using
- a 2 pass solution
- using node-set extension

Regards,
Mukul


--- Wendell Piez <wapiez(_at_)mulberrytech(_dot_)com> wrote:
In the general case, two passes, or a resort to a
node-set extension 
function, is necessary for a clean solution to this,
because the numbering 
depends not on the order and position of nodes in
the source document, but 
in the result.

When we are not reordering the nodes within their
groups, however, one can 
often force this ...

<xsl:value-of

select="count(preceding::item[category=current()/category])+1"/>

but be warned: it can be slowish to execute on large
documents.

No variable reassignment is called for here.

Cheers,
Wendell

James's spec:

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




======================================================================
Wendell Piez                           
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.               
http://www.mulberrytech.com
17 West Jefferson Street                    Direct
Phone: 301/315-9635
Suite 207                                         
Phone: 301/315-9631
Rockville, MD  20850                                
Fax: 301/315-8285

----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing
in SGML and XML

======================================================================


 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