Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "Thomas Stone" <tjbooker@-------------->
To:
Date: 1/1/2007 8:24:00 PM
> ----- 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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent