Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 11th, 2006, 02:23 PM
Registered User
 
Join Date: Jan 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default recursive XSLT Help

Hi I am trying to do the following with a xslt page for xml output. I am not doing html rendering and I need all the elements to output

1) Have a flat DB Table that I read into XML. It comes out as
<NODES>
  <NODE>
     <name>A</name>
     <id>1</id>
     <parent>Root</parent>
  </NODE>
  <NODE>
     <name>B</name>
     <id>2</id>
     <parent>1</parent>
  </NODE>
  <NODE>
     <name>C</name>
     <id>3</id>
     <parent>2</parent>
  </NODE>
  <NODE>
     <name>D</name>
     <id>4</id>
     <parent>Root</parent>
  </NODE>
  <NODE>
     <name>E</name>
     <id>5</id>
     <parent>4</parent>
  </NODE>
  <NODE>
     <name>F</name>
     <id>6</id>
     <parent>4</parent>
  </NODE>
</NODES>

2) need to change the format to this so I can use it in a web control
This is a nested xml file that shows the relationship
<NODES>
  <NODE>
     <name>A</name>
     <id>1</id>
     <parent>Root</parent>
     <NODE>
        <name>B</name>
        <id>2</id>
        <parent>1</parent>
        <NODE>
           <name>C</name>
           <id>2</id>
           <parent>Root</parent>
        </NODE>
     </NODE>
  </NODE>
  <NODE>
     <name>D</name>
     <id>4</id>
     <parent>Root</parent>
     <NODE>
        <name>E</name>
        <id>5</id>
        <parent>4</parent>
     </NODE>
     <NODE>
        <name>F</name>
        <id>6</id>
        <parent>4</parent>
     </NODE>
  </NODE>
</NODES>

Thanks,
Ben
 
Old January 11th, 2006, 03:08 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You want something like this:

<xsl:template match="/">
  <xsl:apply-templates select="/NODES/NODE[parent='Root']"/>
</xsl:template>

<xsl:template match="NODE">
  <NODE>
    <xsl:copy-of select="*"/>
    <xsl:apply-templates select="/NODES/NODE[parent=current()/id]"/>
  </NODE>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 11th, 2006, 03:50 PM
Registered User
 
Join Date: Jan 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael,

I modified (to what I need) and tested out your transform in altovaXML and CookTop xslt parsers. This is exactly the solution I needed. I will check out your book!! Hopefully you have a recursive chapter.


Cheers,
Ben






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with a recursive Query!!! dbayona SQL Server 2005 1 December 20th, 2007 07:40 AM
Recursive Template Help bucky483 XSLT 1 July 20th, 2007 12:21 PM
Recursive Coding arnabghosh Classic ASP Professional 2 July 9th, 2007 02:06 AM
Recursive Function MargateFan XSLT 2 May 4th, 2006 02:52 AM
Recursive Transform chuck.boyer XSLT 0 December 5th, 2005 05:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.