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

Subject: Re: [xsl] looping problem, <xsl: for-each>??
From: Mukul Gandhi <mukulgw3@xxxxxxxxx>
Date: Thu, 9 Oct 2003 10:05:06 -0700 (PDT)
Hi Wendell,
  I was able to generate numbering 1,2,3,4.. 

I applied your suggestion to store an intermediate
tree fragment in a variable, and then converting the
variable into a nodeset. By iterating the nodeset, I
am able to generate numbers 1,2,3,4.. 

The XSL is --

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>

<xsl:key name="x" match="/rss/channel/item"
<xsl:template match="/">
  <xsl:variable name="treeFrag">
      <xsl:for-each select="rss/channel/item">
	<xsl:if test="generate-id(.) = generate-id(key('x',
	  <h1>						    <xsl:value-of select="category"/>
	  <xsl:for-each select="key('x', category)">
	      <xsl:value-of select="description"/>
    <xsl:if test="name(preceding-sibling::*[1]) =
	<xsl:value-of select="preceding-sibling::*[1]" />
    ITEM<xsl:value-of select="position()"/>
<xsl:value-of select="."/>


In the above solution, though numbers are getting
generated properly, but to output <h1> tags at the
right place, I had to write a slightly complex syntax
* xsl:if test="name(preceding-sibling::*[1]) = 'h1'" *

I have used the Xalan nodeset extension function.  The
syntax -- xalan:nodeset, can be replaced by
vendor:node-set for a different XSLT processor..

Would also like to have your comments if any to
improve the above XSL.

This _also_ completes my answer..


--- Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> wrote:
> The two-pass solution would simply be:
> pass 1: sort and create output
> pass 2: number
> The node-set-extension-based solution would be the
> same, except that pass 1 
> would be bound to a variable, then that variable's
> value (a 
> result-tree-fragment) changed to a node-set (in a
> second variable 
> declaration); then you'd apply templates to that
> node set to get the numbering.
> I'd go into more detail but I'm kinda swamped at the
> moment.... :->
> Cheers,
> Wendell
> Wendell Piez                           
> mailto:wapiez@xxxxxxxxxxxxxxxx
> Mulberry Technologies, Inc.               
> 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: 

Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

 XSL-List info and archive:

Current Thread