XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Glenn MeadowsSubject: Creating a XML document with nested nodes
Author: Glenn Meadows
Date: 25 Aug 2006 05:25 PM
Hello,

Using XSLT and the mapper utility with Stylus Studio, I have created a XML document with a list of 2 fields being TASK_NAME and TASK_OUTLINE_LEVEL. The TASK_NAME is just that, the description of a task. The TASK_OUTLINE_LEVEL indicates the hierarchy of each task in a tree structure with 0 being the top-most node and 1, 2, 3, etc. being nodes further inside the tree.

I have attached a source XML file and the XSLT file that renders output to a target XML file.

I am doing a eval of SS and so I am new at all this. Could someone tell me if this is achievable?

Thanks,
- Glenn


Unknowntasklist.xsl
XSLT document to render XML target file

Postnext
Glenn MeadowsSubject: Creating a XML document with nested nodes
Author: Glenn Meadows
Date: 28 Aug 2006 04:44 PM
My XML file did not get attached to the first message, so here it is.


Unknowntasklist.xml
XML file

Postnext
Glenn MeadowsSubject: Creating a XML document with nested nodes
Author: Glenn Meadows
Date: 28 Aug 2006 04:58 PM
Thought I might add some additional clarity as to what I am looking for.

A target XML file with a tree structure defined as follows;

<node1>Summary Task
<node2>task1</node2>
<node3>task2
<node4>task3</node4>
<node5>task4</node5>
</node3>
<node6>task5</node6>
</node1>

which would allow a tree control to be populated with this tree structure;

Summary Task
task1
task2
task3
task4
task5

Posttop
Minollo I.Subject: Creating a XML document with nested nodes
Author: Minollo I.
Date: 29 Aug 2006 09:54 AM
Glenn,
you can try code similar to the following; I'm assuming that the position of the nodes in the document is what is determinint the parent/child relationship, as long as the outline-level data.

<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
<xsl:for-each select="dataroot/MSP_TASKS[not(TASK_OUTLINE_LEVEL)]">
<!-- what to do with tasks with no outline level (and no name)? -->
</xsl:for-each>
<xsl:for-each select="dataroot/MSP_TASKS">
<xsl:if test="TASK_OUTLINE_LEVEL=1">
<node name="{TASK_NAME}">
<xsl:call-template name="getChildren">
<xsl:with-param name="level" select="2"/>
<xsl:with-param name="fromPosition" select="position()+1"/>
</xsl:call-template>
</node>
</xsl:if>
</xsl:for-each>
</dataroot>
</xsl:template>

<xsl:template name="getChildren">
<xsl:param name="level"/>
<xsl:param name="fromPosition"/>
<xsl:choose>
<xsl:when test="/dataroot/MSP_TASKS[$fromPosition]/TASK_OUTLINE_LEVEL = $level">
<node name="{/dataroot/MSP_TASKS[$fromPosition]/TASK_NAME}">
<xsl:call-template name="getChildren">
<xsl:with-param name="level" select="$level+1"/>
<xsl:with-param name="fromPosition" select="$fromPosition+1"/>
</xsl:call-template>
</node>
<xsl:call-template name="getChildren">
<xsl:with-param name="level" select="$level"/>
<xsl:with-param name="fromPosition" select="$fromPosition+1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="/dataroot/MSP_TASKS[$fromPosition]/TASK_OUTLINE_LEVEL > $level">
<xsl:call-template name="getChildren">
<xsl:with-param name="level" select="$level"/>
<xsl:with-param name="fromPosition" select="$fromPosition+1"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.