xsl-list
[Top] [All Lists]

Re: [xsl] Creating a classification hierarcy by using XSLT to nest similarly named elements

2007-01-01 13:23:59
----- Original Message -----
From: "Chris Coyle" <chriscoyle(_at_)yahoo(_dot_)com>
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(Attribute[(_at_)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[(_at_)name='CLASSIFICATION_ID']"/>
        
<xsl:apply-templates 
select="//Transaction/Response/MasterCatalogRecord/EntityData[starts-with(Attribute[(_at_)name='CLASSIFICATION_ID'],$main_id)
 and string-length(Attribute[(_at_)name='CLASSIFICATION_ID']) > 
string-length($main_id)]"/>



-- 
___________________________________________________
Search for products and services at:
http://search.mail.com


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--