Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 19th, 2003, 01:11 AM
Registered User
 
Join Date: Nov 2003
Location: arlington, texas, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help in creating folder tree

Hi Friends,
    I need help in creating a folder tree like structure from an xml file. My xml file looks like this.

<topic id = "living part">
  <baseName>
     <baseNameString>
         Living Part
     </baseNameString>
  </baseName>
</topic>
<topic id = "animal">
  <instanceOf>
     <topicRef xlink:href="#living part"/>
  </instanceOf>
  <baseName>
     <baseNameString>
         Animal
     </baseNameString>
  </baseName>
</topic>
<topic id = "carnivorous">
  <instanceOf>
     <topicRef xlink:href="#animal"/>
  </instanceOf>
  <baseName>
     <baseNameString>
         Carnivorous
     </baseNameString>
  </baseName>
</topic>
<topic id = "herbivorous">
  <instanceOf>
     <topicRef xlink:href="#animal"/>
  </instanceOf>
  <baseName>
     <baseNameString>
         Herbivorous
     </baseNameString>
  </baseName>
</topic>
...

My Output should be like,
    Living Part
       Animal
          Carnivorous
          Herbivorous
          ...
       ...

Grateful to any suggestion.

Thanks,
Vel.
Reply With Quote
  #2 (permalink)  
Old November 19th, 2003, 06:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Nor Hachin, Kotayk, Armenia.
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Hi,

I've added DTD to your XML doc (you can make it more "granular"). It's better to define an attribute 'id' as of type ID (and hence you can't use whitespace there):

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE doc[
<!ELEMENT doc (topic)+>
<!ELEMENT topic ANY>
<!ATTLIST topic id ID #REQUIRED>
<!ELEMENT baseNameString ANY>
<!ELEMENT baseName ANY>
<!ELEMENT instanceOf ANY>
<!ELEMENT topicRef ANY>
<!ATTLIST topicRef xlink:href CDATA #REQUIRED>
]>
<doc xmlns:xlink="xlink-URI-here">
<topic id = "livingpart">
  <baseName>
     <baseNameString>
         Living Part
     </baseNameString>
  </baseName>
</topic>
<topic id = "animal">
  <instanceOf>
     <topicRef xlink:href="#livingpart"/>
  </instanceOf>
  <baseName>
     <baseNameString>
         Animal
     </baseNameString>
  </baseName>
</topic>
<topic id = "carnivorous">
  <instanceOf>
     <topicRef xlink:href="#animal"/>
  </instanceOf>
  <baseName>
     <baseNameString>
         Carnivorous
     </baseNameString>
  </baseName>
</topic>
<topic id = "herbivorous">
  <instanceOf>
     <topicRef xlink:href="#animal"/>
  </instanceOf>
  <baseName>
     <baseNameString>
         Herbivorous
     </baseNameString>
  </baseName>
</topic>
</doc>
And the stylesheet is:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="xlink-URI-here">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <xsl:apply-templates select="doc/topic[@id = 'livingpart']"/>
    </xsl:template>
    <xsl:template match="topic">
        <xsl:element name="{@id}">
            <xsl:apply-templates select="/doc/topic[substring-after(instanceOf/topicRef/@xlink:href, '#') = current()/@id]"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>
I've written this quickly, so one can find another more elegant solution.

Regards,
Armen
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error creating new folder in asp kingbee Classic ASP Basics 2 March 10th, 2006 05:09 AM
Creating a Tree Structure pazzuzu C++ Programming 2 February 26th, 2005 12:07 PM
Creating Folder On Server Prabhakar_dt Classic ASP Basics 1 December 29th, 2004 05:07 AM
Creating a tree view ravi_talk Classic ASP Basics 0 September 27th, 2003 10:58 PM



All times are GMT -4. The time now is 06:36 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.