Subject: Re: [xsl] XSL Template Match using z:row attributes From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 14 Dec 2001 11:46:35 +0000 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSL Template Match using , Michael McCarty | Thread | Re: [xsl] XSL Template Match using , Michael McCarty |
[xsl] outputting   to HTML (abo, Aniceto López | Date | [xsl] problems with position(), rafael vazquez |
Month |