Re: [xsl] XSL Template Match using z:row attributes

Subject: Re: [xsl] XSL Template Match using z:row attributes
From: "Michael McCarty" <mccarty@xxxxxxxxxx>
Date: Fri, 14 Dec 2001 14:29:10 -0800
Wow.  Thanks Jeni.  That worked perfectly.  I think I'm finally starting
to get it or at least the light bulb is a bit brighter. =:-)

Thank you, everyone, for all your help.

Mike =:-)


---- Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> wrote:
> Hi Mike,
> 
> > I'm trying to build a heirarchy based on the @LEVEL attrbiute in
> my
> > input XML.
> 
> Actually, it looks as though you're trying to build a hierarchy based
> on the CATEGORYID and PARENTID attributes of your z:row elements?
> 
> To do this, create a key that indexes all the z:row elements based
> on
> their PARENTID:
> 
> <xsl:key name="rows-by-parent" match="z:row" use="@PARENTID" />
> 
> That means that if you do:
> 
>   key('rows-by-parent', 1)
> 
> you get all the z:rows whose PARENTID attribute has a value of 1, i.e.
> all those z:rows whose parent has a CATEGORYID of 1.
> 
> You can then create a template that generates the output for a
> particular row: a div element with a level attribute equal to the
> value of its LEVEL attribute:
> 
> <xsl:template match="z:row">
>   <div level="{LEVEL}">
>     ...
>   </div>
> </xsl:template>
> 
> With the div containing the value of its CATEGORYNAME attribute:
> 
> <xsl:template match="z:row">
>   <div level="{LEVEL}">
>     <xsl:value-of select="@CATEGORYNAME" />
>     ...
>   </div>
> </xsl:template>
> 
> Followed by whatever you get when you apply templates to its
> 'children'. You can find its 'children' using the key you just set
> up,
> with the current row's CATEGORYID as the second argument:
> 
> <xsl:template match="z:row">
>   <div level="{LEVEL}">
>     <xsl:value-of select="@CATEGORYNAME" />
>     <xsl:apply-templates
>          select="key('rows-by-parent', @CATEGORYID)" />
>   </div>
> </xsl:template>
> 
> To start the process off, you need to apply templates to the first
> row
> in the hierarchy. That's the row whose PARENTID is 0. So you can use:
> 
> <xsl:template match="rs:data">
>   <xsl:apply-templates select="key('rows-by-parent', 0)" />
> </xsl:template>
> 
> I hope that helps,
> 
> Jeni
> 
> ---
> Jeni Tennison
> http://www.jenitennison.com/
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 

__________________________________________________
FREE voicemail, email, and fax...all in one place.
Sign Up Now! http://www.onebox.com


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


Current Thread