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
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Greg AusleySubject: Nesting Tables and Sub-Tables
Author: Greg Ausley
Date: 24 Jan 2005 08:39 PM
Originally Posted: 24 Jan 2005 08:36 PM
** Not sure why this is formatting wrong... Went to edit it and can't fix it... sorry ** Hi. We are new to Stylus Studio. Can you please lead us in the right direction on the following: We want to create a recordset and display a profile for each record. Within the profile, we would like to nest a sub-table of data related to the record for that profile.<br> Sample Data: Contact Table has info about a contact<br> ContactGroup Table has a link between ContactIDs and Groups. How should we proceed with building this in the WYSIWIG program? Do we need a single XML file, or can we have a main XML and a sub XML filtered for ContactID = Record.ContactID? How do you build a table with data where you don't know the quantity of records in that table? Are there any developers out there that want to contract with our firm to get us going with this new technology and help us build reports using this technology?<br> Thanks. Greg

Posttop
Ivan PedruzziSubject: Nesting Tables and Sub-Tables
Author: Ivan Pedruzzi
Date: 28 Jan 2005 12:56 AM
Hi Greg,

Assuming your database looks like this

Contact (ID, CONTACT_NAME)
Group (ID, GROUP_NAME)
ContactGroup (ContactID, GroupID)


Running the following query using the Stylus Studio SQL/XML editor (DB to XML Data Source)


SELECT
XMLELEMENT(name "GROUP",
XMLELEMENT(name "NAME", g.GROUP_NAME),
(
SELECT
XMLELEMENT(name "CONTACTS",
XMLELEMENT(name "NAME", c.CONTACT_NAME)
)
FROM Contact c, ContactGroup cg WHERE cg.GroupID = g.ID AND cg.ContactID = c.ID
)
)
FROM Group g


Generates the following XML result

<root>
<GROUP>
<NAME>AAA</NAME>
<CONTACTS>
<NAME>John</NAME>
<NAME>Bill</NAME>
</CONTACTS>
</GROUP>

</root>

Now you can transform the above document using the XSLT below to generate an HTML page

Hope this helps
Ivan


<?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="/">
<html><head/>
<body>
<table width="100%" border="1">
<tbody>
<xsl:for-each select="root/GROUP">
<tr>
<td width="50%">
<xsl:value-of select="NAME"/>
</td>
<td width="50%">
<table width="100%" border="1">
<tbody>
<xsl:for-each select="CONTACTS/NAME">
<tr>
<td width="50%">
<xsl:value-of select="."/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

 
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.