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
Rob ClassenSubject: Hierarchical XML Data Set
Author: Rob Classen
Date: 18 Oct 2006 09:07 PM
Originally Posted: 18 Oct 2006 09:05 PM
Please forgive me if this is naive or just a plain easy question, for I am a newbie to XML and XSLT files. I am in the process of buying Stylus Studio to help me learn. My XML data is a hierarchy with an indeterminant number of levels deep. I have the following XML data and wish to create an HTML document that shows the hierarchy something as follows:

10144 Alloc:100 Land:0
----10063 Alloc:33 Land:25
--------10143 Alloc:100 Land:100
--------10146 Alloc:100 Land:100

10147 Alloc:100 Land:25

What should the XSLT look like?

Thanks in advance for any help.

Rob



XML DATA
------------------------------
<?xml version="1.0"?><!DOCTYPE Active []>
<Active xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="XMLData.xsd">
<Prop>
<ID>10144</ID>
<AllocatedPercent>100</AllocatedPercent>
<LandPercent>0</LandPercent>
<BldgPercent>0</BldgPercent>
<PPEPercent>0</PPEPercent>
<Prop>
<ID>10063</ID>
<AllocatedPercent>33</AllocatedPercent>
<LandPercent>25</LandPercent>
<BldgPercent>50</BldgPercent>
<PPEPercent>25</PPEPercent>
<Prop>
<ID>10143</ID>
<AllocatedPercent>100</AllocatedPercent>
<LandPercent>100</LandPercent>
<BldgPercent>100</BldgPercent>
<PPEPercent>100</PPEPercent>
</Prop>
<Prop>
<ID>10146</ID>
<AllocatedPercent>100</AllocatedPercent>
<LandPercent>100</LandPercent>
<BldgPercent>100</BldgPercent>
<PPEPercent>100</PPEPercent>
</Prop>
</Prop>
</Prop>
<Prop>
<ID>10147</ID>
<AllocatedPercent>100</AllocatedPercent>
<LandPercent>25</LandPercent>
<BldgPercent>100</BldgPercent>
<PPEPercent>100</PPEPercent>
</Prop>
</Active>



XML SCHEMA
---------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Active">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Prop"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Prop">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Prop"/>
<xs:element ref="AllocatedPercent"/>
<xs:element ref="BldgPercent"/>
<xs:element ref="ID"/>
<xs:element ref="LandPercent"/>
<xs:element ref="PPEPercent"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="AllocatedPercent" type="xs:integer"/>
<xs:element name="BldgPercent" type="xs:integer"/>
<xs:element name="ID" type="xs:integer"/>
<xs:element name="LandPercent" type="xs:integer"/>
<xs:element name="PPEPercent" type="xs:integer"/>
</xs:schema>


XSLT (So far...)
---------------------------------
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>


<xsl:template match="Prop">
<p>&#160;</p>
<p>--&gt;Property:
<xsl:value-of select="ID"/>&#160;&#160; Allocation:&#160;
<xsl:value-of select="AllocatedPercent"/>&#160;&#160; Land:&#160;
<xsl:value-of select="LandPercent"/>
<xsl:for-each select="Prop">
<xsl:apply-templates select="Prop"/>
</xsl:for-each>
</p>
</xsl:template>

</xsl:stylesheet>

Postnext
Ivan PedruzziSubject: Hierarchical XML Data Set
Author: Ivan Pedruzzi
Date: 18 Oct 2006 10:35 PM
Hi Rob,

See if the following works for you

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head/>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="Prop">
<ul>
<xsl:variable name="Prop" select="."/>
<li>
<xsl:value-of select="concat(ID, ' Alloc ', AllocatedPercent, ' Land ', LandPercent)"/>
</li>
<xsl:apply-templates select="Prop"/>
</ul>
</xsl:template>
</xsl:stylesheet>


Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Rob ClassenSubject: Hierarchical XML Data Set
Author: Rob Classen
Date: 18 Oct 2006 11:06 PM
Originally Posted: 18 Oct 2006 11:05 PM
Looks like it is going to work great! Thanks so much for the help.

One more thing... The ID field stored in the XML is not very useful but the name that this refers to would be so much better to be displayed. The problem is that the name is stored in a table called tblProperty in a SQL 2005 database. What would be the best way to join back to this field so I can add it to my XML data?

Is there a way I can do this in XSLT or XQuery if I get tblProperty in a seperate XML?

Any thoughts would be appreciated.

Rob

Posttop
Ivan PedruzziSubject: Hierarchical XML Data Set
Author: Ivan Pedruzzi
Date: 18 Oct 2006 11:32 PM
You will need to use DataDirect XQuery to merge relational data with your input XML.

Hava a look at http://www.stylusstudio.com/xquery/datadirect_xquery.html


Ivan Pedruzzi
Stylus Studio Team

 
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.