Subject: Re: [xsl] Creating a classification hierarcy by using XSLT to nest similarly named elements From: "Thomas Stone" <tjbooker@xxxxxxxxxxxxxx> Date: Mon, 01 Jan 2007 12:23:38 -0800 |
> ----- Original Message ----- > From: "Chris Coyle" <chriscoyle@xxxxxxxxx> > So far, I have the following for my XSLT stylesheet: > <xsl:apply-templates select="//Transaction/Response"/> ... > <xsl:template match="Response"> > <xsl:for-each select="MasterCatalogRecord/EntityData"> Thanks for you question. It would seem that you are looking for the EntityData records and not the Response records. Using a template to respond to that particular record will be clearer. <xsl:apply-templates select="//Transaction/Response/MasterCatalogRecord/EntityData"> ... <xsl:template match="EntityData"> > In order to achieve the nesting of elements I desire, > I believe I need to use recursion. I just don't know > how to express it im my stylesheet. Any suggestions > will be greatly appreciated. This looks similar to a "self-join" database query. You are selecting a main EntityData record and displaying it then finding that record's sub-EntityData record. This would be much more efficient pulling from a database with indexes than after-the-fact in XML. But that's a different forum;-) Your recursion is apparently one level deep, but the template doesn't have to know that! Your apply-templates query needs to select your main records that do not have any parent-EntityData records. I assume that this would be the CLASSIFICATION_ID Attribute entities with only a two-character string. <xsl:apply-templates select="//Transaction/Response/MasterCatalogRecord/EntityData[string-length(A ttribute[@name='CLASSIFICATION_ID'])=2]"/> Within your template, which now matches "EntityData", you will open the record tag and put out attributes to it. Then, before you close the record tag, insert the following two lines to select this record's sub-EntityData records. <xsl:variable name="main_id" select="Attribute[@name='CLASSIFICATION_ID']"/> <xsl:apply-templates select="//Transaction/Response/MasterCatalogRecord/EntityData[starts-with(Att ribute[@name='CLASSIFICATION_ID'],$main_id) and string-length(Attribute[@name='CLASSIFICATION_ID']) > string-length($main_id)]"/> -- ___________________________________________________ Search for products and services at: http://search.mail.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Creating a classification hie, Chris Coyle | Thread | Re: [xsl] Creating a classification, Chris Coyle |
[xsl] Creating a classification hie, Chris Coyle | Date | Re: [xsl] Re: Cosmetic sorting, Harry Liljeström |
Month |