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

Re: XSL, SQL, and trees (again)

Subject: Re: XSL, SQL, and trees (again)
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Thu, 27 Jul 2006 22:16:07 +0530
xsl sql
Hi Phill,
 Here is a XSLT 1.0 solution to convert,

<directories>
<item>
  <id>1</id>
  <name>About</name>
  <path>1</path>
</item>
<item>
  <id>2</id>
  <name>Services</name>
  <path>2</path>
</item>
<item>
  <id>3</id>
  <name>Environmental</name>
  <path>2.1</path>
</item>
<item>
  <id>4</id>
  <name>Landscaping</name>
  <path>2.2</path>
</item>
</directories>

into,

<directories>
  <directory name="About"/>
  <directory name="Services">
     <directory name="Environmental"/>
     <directory name="Landscaping"/>
  </directory>
</directories>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/directories">
 <directories>
   <xsl:for-each select="item[(string-length(path) -
string-length(translate(path, '.', ''))) = 0]">
     <directory name="{name}">
       <xsl:call-template name="re-arrange">
         <xsl:with-param name="nodeset" select="../item" />
         <xsl:with-param name="curr-path" select="path" />
         <xsl:with-param name="no-of-dots" select="1" />
       </xsl:call-template>
     </directory>
   </xsl:for-each>
 </directories>
</xsl:template>

<xsl:template name="re-arrange">
 <xsl:param name="nodeset" />
 <xsl:param name="curr-path" />
 <xsl:param name="no-of-dots" />

 <xsl:for-each select="$nodeset[((string-length(path) -
string-length(translate(path, '.', ''))) = $no-of-dots) and
(starts-with(path, $curr-path))]">
   <directory name="{name}">
     <xsl:call-template name="re-arrange">
      <xsl:with-param name="nodeset" select="$nodeset" />
      <xsl:with-param name="curr-path" select="path" />
      <xsl:with-param name="no-of-dots" select="$no-of-dots + 1" />
     </xsl:call-template>
   </directory>
 </xsl:for-each>

</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

http://gandhimukul.tripod.com

On 7/27/06, Phillip B Oldham <phillip.oldham@xxxxxxxxxx> wrote:
Hi all

I've been looking at the different methods for working with storing
trees in SQL.

At the moment, I'm looking at the 'Materialized Path' technique, and
have a couple of questions regarding XSL.

If I were to have a table along the following lines:

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.