[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Processing Nested Lists

Subject: RE: Processing Nested Lists
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 26 Feb 2007 16:24:09 -0000
RE:  Processing Nested Lists
The structure of your input and output seems to be essentially the same, so
an ordinary recursive tree-walk using apply-templates should do the job:

<xsl:template match="TaxonomyNode">
  <xsl:copy>
  <xsl:copy-of select="@*">
  <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="Description">
  <Description>
     <w:r>
       <w:t><xsl:value-of select="."/></w:t>
     </w:r>
  </Description>
</xsl:template>

Or have I missed something?

Michael Kay
http://www.saxonica.com/
   

> -----Original Message-----
> From: Andy Carr1 [mailto:CARRA@xxxxxxxxxx] 
> Sent: 26 February 2007 16:13
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Processing Nested Lists
> 
> Hi
> 
> Does anybody know how do you process nodes within a tag that 
> are nested to an undefined depth.
> 
> I have a tag structure that looks like this:
> 
> <TaxonomyEntries>
> - - -<TaxonomyNode> (1 to infinity)
> - - - - - -<Description />
> - - - - - -<TaxonomyNode /> (0 to infinity)
> - - -<TaxonomyNode>
> <TaxonomyEntries>
> 
> And I have some XML that looks like this:
> 
> <TopTag>
>    <TaxonomyEntries>
>       <TaxonomyNode name="Arbitrary Name">          -----Top 
> Level Node
>          <Description>any description</Description>
>          <TaxonomyNode name="another name">
>             <TaxonomyNode name="yet another name">
>                <Description>any description</Description>
>                <TaxonomyNode name="and yet another name">
>                   <Description>any description</Description>
>                </TaxonomyNode>
>             </TaxonomyNode>
>          </TaxonomyNode>
>       </TaxonomyNode>
>       <TaxonomyNode name="Arbitrary Name">          -----Top 
> Level Node
>          <Description>any description</Description>
>          <TaxonomyNode name="another name">
>             <Description>any description</Description>
>          </TaxonomyNode>
>       </TaxonomyNode>
>    </TaxonomyEntries>
> </TopTag>
> 
> I need to apply a stylesheet (XSL v2.0) to this XML to create 
> a Table in Word so that each Top Level TaxonomyNode is in a 
> separate Table Row and the children and childrens-children 
> are all nested accordingly with their descriptions displayed.
> 
> <w:tbl>
>    <w:tblPr>
>    <w:tblGrid>
>    <w:tr>
>    <TaxonomyEntries>
>       <w:tr>
>          <w:tc>
>             <w:p>
>                <TaxonomyNode name="Arbitrary Name">
>                   <Description>
>                      <w:r>
>                         <w:t>any description</w:t>
>                      </w:r>
>                   </Description>
>                   <TaxonomyNode name="another name">
>                      <Description>
>                         <w:r>
>                            <w:t>any description</w:t>
>                         </w:r>
>                      </Description>
>                      <TaxonomyNode name="yet another name">
>                         <Description>
>                            <w:r>
>                               <w:t>any description</w:t>
>                            </w:r>
>                         </Description>
>                         <TaxonomyNode name="and yet another name">
>                            <Description>
>                               <w:r>
>                                  <w:t>any description</w:t>
>                               </w:r>
>                            </Description>
>                         </TaxonomyNode>
>                      </TaxonomyNode>
>                   </TaxonomyNode>
>                </TaxonomyNode>
>             </w:p>
>          </w:tc>
>       </w:tr>
>       <w:tr>
>          <w:tc>
>             <w:p>
>                <TaxonomyNode name="Arbitrary Name">
>                   <Description>
>                      <w:r>
>                         <w:t>any description</w:t>
>                      </w:r>
>                   </Description>
>                   <TaxonomyNode name="another name">
>                      <Description>
>                         <w:r>
>                            <w:t>any description</w:t>
>                         </w:r>
>                      </Description>
>                   </TaxonomyNode>
>                </TaxonomyNode>
>             </w:p>
>          </w:tc>
>       </w:tr>
>    </TaxonomyEntries>
> <w:tbl>
> 
> Could any one give me some pointers on how to achieve this 
> nesting. It seems to me that some sort of recursion is in 
> order but I'm not sure how to implement it when there is no 
> fixed depth to the nesting i.e there is no break-out parameter.
> 
> Hopefully
> Andy
> 
> 
> 
> 
> 
> 
> 
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales 
> with number 741598. 
> Registered office: PO Box 41, North Harbour, Portsmouth, 
> Hampshire PO6 3AU

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.