473,471 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XSLT XML-HTML Transformation using grouping

Is there anyway to generate this type of resulting HTML table from
this XML using XSLT? Basically I need to be able to consult 2 trees of
data to generate the HTML, but I have not been able to figure out how
to do so. There is supposed to be a way of using templates and the key
function to do grouping, but can it be done with 2 different trees? If
so, are there any examples of such things

Thanks for any help,

Kevin

***

HTML Table

chef 1 chef 2 chef 3
must: make.pizza
pour.milk
maybe: make.orange.juice make.ice.cream make.martini
never: make.apple.pie
***

XML File
<?xml version="1.0" encoding="LATIN1" standalone="yes" ?>
<!--
<!DOCTYPE housework.definition PUBLIC "house work xml"
"housework.dtd">

-->
<housework.definition housework.name="kitchen work"
docclass.name="house work">
<element.for.housework.def.list>
<element.for.housework.def element.name="make.pizza" presence="must"
/>
<element.for.housework.def element.name="pour.milk" presence="must"
/>
<element.for.housework.def element.name="make.orange.juice"
presence="maybe" />
<element.for.housework.def element.name="make.apple.pie"
presence="never" />
<element.for.housework.def element.name="make.ice.cream"
presence="maybe" />
<element.for.housework.def element.name="make.martini"
presence="maybe" />
</element.for.housework.def.list>
<sequence.def.list>
<sequence.def sequence="stage 1">
<sequence.def.role role="chef 1">
<element.for.sequence.def.role element="make.pizza" />
<element.for.sequence.def.role element="pour.milk" />
<element.for.sequence.def.role element="make.orange.juice" />
</sequence.def.role>
<sequence.def.role role="chef 2">
<element.for.sequence.def.role element="make.apple.pie" />
<element.for.sequence.def.role element="make.ice.cream" />
</sequence.def.role>
<sequence.def.role role="chef 3">
<element.for.sequence.def.role element="make.martini" />
</sequence.def.role>
</sequence.def>
</sequence.def.list>
</housework.definition>
Jul 20 '05 #1
3 2408
Hi Kevin,

The only distinct/grouping I can see if the values of @presence?

Try something like...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:key name="kDistinctPresence" match="element.for.housework.def"
use="@presence"/>

<xsl:template match="/">
<html>
<body>
<xsl:variable name="chefs"
select="/housework.definition/sequence.def.list/sequence.def/sequence.def.ro
le"/>
<table border="1">
<!-- do the chef header row -->
<tr>
<th/>
<xsl:for-each select="$chefs">
<th>
<xsl:value-of select="@role"/>
</th>
</xsl:for-each>
</tr>
<!-- now do the rows for each distinct @presence -->
<xsl:apply-templates
select="/housework.definition/element.for.housework.def.list/element.for.hou
sework.def[generate-id() =
generate-id(key('kDistinctPresence',@presence))]">
<xsl:with-param name="chefs" select="$chefs"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>

<xsl:template match="element.for.housework.def">
<xsl:param name="chefs"/>
<xsl:variable name="this-presence"
select="key('kDistinctPresence',@presence)/@element.name"/>
<tr>
<th align="right">
<xsl:value-of select="@presence"/>
<xsl:text>:</xsl:text>
</th>
<!-- now do columns for each chef with this @presence value -->
<xsl:for-each select="$chefs">
<td>
<!-- look for matches withing this chef of the current @presence -->
<xsl:for-each select="element.for.sequence.def.role/@element[. =
$this-presence]">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<br/>
</xsl:if>
</xsl:for-each>
</td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Kevin Brown" <kb****@gmail.com> wrote in message
news:55**************************@posting.google.c om...
Is there anyway to generate this type of resulting HTML table from
this XML using XSLT? Basically I need to be able to consult 2 trees of
data to generate the HTML, but I have not been able to figure out how
to do so. There is supposed to be a way of using templates and the key
function to do grouping, but can it be done with 2 different trees? If
so, are there any examples of such things

Thanks for any help,

Kevin

***

HTML Table

chef 1 chef 2 chef 3
must: make.pizza
pour.milk
maybe: make.orange.juice make.ice.cream make.martini
never: make.apple.pie
***

XML File
<?xml version="1.0" encoding="LATIN1" standalone="yes" ?>
<!--
<!DOCTYPE housework.definition PUBLIC "house work xml"
"housework.dtd">

-->
<housework.definition housework.name="kitchen work"
docclass.name="house work">
<element.for.housework.def.list>
<element.for.housework.def element.name="make.pizza" presence="must"
/>
<element.for.housework.def element.name="pour.milk" presence="must"
/>
<element.for.housework.def element.name="make.orange.juice"
presence="maybe" />
<element.for.housework.def element.name="make.apple.pie"
presence="never" />
<element.for.housework.def element.name="make.ice.cream"
presence="maybe" />
<element.for.housework.def element.name="make.martini"
presence="maybe" />
</element.for.housework.def.list>
<sequence.def.list>
<sequence.def sequence="stage 1">
<sequence.def.role role="chef 1">
<element.for.sequence.def.role element="make.pizza" />
<element.for.sequence.def.role element="pour.milk" />
<element.for.sequence.def.role element="make.orange.juice" />
</sequence.def.role>
<sequence.def.role role="chef 2">
<element.for.sequence.def.role element="make.apple.pie" />
<element.for.sequence.def.role element="make.ice.cream" />
</sequence.def.role>
<sequence.def.role role="chef 3">
<element.for.sequence.def.role element="make.martini" />
</sequence.def.role>
</sequence.def>
</sequence.def.list>
</housework.definition>

Jul 20 '05 #2
Kevin Brown <kb****@gmail.com> wrote:
Is there anyway to generate this type of resulting HTML table from
this XML using XSLT? Basically I need to be able to consult 2 trees of
data to generate the HTML, but I have not been able to figure out how
to do so. There is supposed to be a way of using templates and the key
function to do grouping, but can it be done with 2 different trees? If
so, are there any examples of such things

Thanks for any help,

Kevin

***

HTML Table

chef 1 chef 2 chef 3
must: make.pizza
pour.milk
maybe: make.orange.juice make.ice.cream make.martini
never: make.apple.pie


Why don't you convert your XML into arrays, ie.
must=( make.pizza pour.milk )
maybe=( make.orange.juice make.ice.cream make.martini )
never=( make.apple.pie )
and
chef1=( make.pizza pour.milk make.orange.juice )
chef2=( make.ice.cream make.apple.pie )
chef3=( make.martini )

Then, you can cross-check as you print them out.

--
William Park <op**********@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
Jul 20 '05 #3
Thanks guys, you've been a big help!

William Park <op**********@yahoo.ca> wrote in message news:<2p************@uni-berlin.de>...
Kevin Brown <kb****@gmail.com> wrote:
Is there anyway to generate this type of resulting HTML table from
this XML using XSLT? Basically I need to be able to consult 2 trees of
data to generate the HTML, but I have not been able to figure out how
to do so. There is supposed to be a way of using templates and the key
function to do grouping, but can it be done with 2 different trees? If
so, are there any examples of such things

Thanks for any help,

Kevin

***

HTML Table

chef 1 chef 2 chef 3
must: make.pizza
pour.milk
maybe: make.orange.juice make.ice.cream make.martini
never: make.apple.pie


Why don't you convert your XML into arrays, ie.
must=( make.pizza pour.milk )
maybe=( make.orange.juice make.ice.cream make.martini )
never=( make.apple.pie )
and
chef1=( make.pizza pour.milk make.orange.juice )
chef2=( make.ice.cream make.apple.pie )
chef3=( make.martini )

Then, you can cross-check as you print them out.

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sven | last post by:
Hi I have the following XML & XSLT: XML: <?xml version="1.0" encoding="utf-8"?> <Source Source="IBM"> <Detail> <UserID></UserID>
1
by: Mohit | last post by:
Hi Friends I have to call 1 of the 2 child XSLT files from the Main XSLT file based on some criteria. I want one child XSLT file will be executed by version 1 of XSLT processor and the other by...
3
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim...
7
by: RC | last post by:
First, let me say I couldn't find a group discuss XML/XSLT. So I only choose the closest groups to post this message. Here is part of my *.xsl file <xsl:stylesheet...
7
by: pintihar | last post by:
Hi, As a follow on from an earlier post I have another question about xslt. Is it possible to create the stylsheet programatically? Is this sensible? In the first phase I needed to map element...
2
by: Gibson | last post by:
Hi all, i transform xml A to xml B with an xslt. Is it possible to use that xslt to tranform xml B to xml A? Or exist tools to create a corresponding xslt B from the original xslt? Thanks for...
1
by: jrwarwick | last post by:
Hello, I believe I have uncovered a bug in the .Net XSLT engine to do with 'for' loops in XSLT. Here are the steps to reproduce it: -Create A new webform project. -Add the xml file...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
0
by: ManWithNoName | last post by:
The following question is related to this thread: XSLT, document() function, filename, read non-standard/English characters (like µ) I have a XML file with a non-English character in its name...
2
by: astroboiii | last post by:
New to the whole xml thing and finding w3schools to be an excellent resource. Now down to my question: I have several xml files I need to parse through and grab relevant information from and...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.