473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help with XSL to make HTML table

Hi: I'm new with this & need help creating a XSL table that looks
like the following:
---------------------------------------------------------
| | | | | |
|Title |CrossCut |Institution |START |END |
| | | | | |
| | |PI | | |
| | | | | |
|Project| | | | |
|Summary| | | | |
---------------------------------------------------------

XML :

<Programs>
<Title>DETECTING AND BLOCKING</Title>
<CrossCut>BASE</CrossCut>
<PI>John Jones</PI>
<Institution>INSTITUTE</Institution>
<Project_Summary>build an effective</Project_Summary>
<Start>2004-09-15T00:00:00</Start>
<End>2006-09-14T00:00:00</End>
</Programs>
<Programs>
<Title>NETWORKS</Title>
<CrossCut>BASE</CrossCut>
<PI>Mary QuiteContrary</PI>
<Institution>BOSTON UNIVERSITY</Institution>
<Project_Summary>This application describes an
important</Project_Summary>
<Start>2004-08-15T00:00:00</Start>
<End>2007-08-14T00:00:00</End>
</Programs>
<Programs>
<Title>NETWORKS</Title>
<CrossCut>BASE</CrossCut>
<PI>Harry Pit</PI>
<Institution>University</Institution>
<Project_Summary>This application describes an
important</Project_Summary>
<Start>2004-08-15T00:00:00</Start>
<End>2007-08-14T00:00:00</End>
</Programs>
The desired effect will be to sorta group by Title (see that two
titles are same) with subsequent details spanning the row.

Thanks very much for any help I could really use it-- Ginger
Jul 20 '05 #1
6 3644
Virginia Kirkendall <vk*********@hotmail.com> wrote:
Hi: I'm new with this & need help creating a XSL table that looks
like the following:
---------------------------------------------------------
| | | | | |
|Title |CrossCut |Institution |START |END |
| | | | | |
| | |PI | | |
| | | | | |
|Project| | | | |
|Summary| | | | |
---------------------------------------------------------

XML :

<Programs>
<Title>DETECTING AND BLOCKING</Title>
<CrossCut>BASE</CrossCut>
<PI>John Jones</PI>
<Institution>INSTITUTE</Institution>
<Project_Summary>build an effective</Project_Summary>
<Start>2004-09-15T00:00:00</Start>
<End>2006-09-14T00:00:00</End>
</Programs>
<Programs>
<Title>NETWORKS</Title>
<CrossCut>BASE</CrossCut>
<PI>Mary QuiteContrary</PI>
<Institution>BOSTON UNIVERSITY</Institution>
<Project_Summary>This application describes an
important</Project_Summary>
<Start>2004-08-15T00:00:00</Start>
<End>2007-08-14T00:00:00</End>
</Programs>
<Programs>
<Title>NETWORKS</Title>
<CrossCut>BASE</CrossCut>
<PI>Harry Pit</PI>
<Institution>University</Institution>
<Project_Summary>This application describes an
important</Project_Summary>
<Start>2004-08-15T00:00:00</Start>
<End>2007-08-14T00:00:00</End>
</Programs>
The desired effect will be to sorta group by Title (see that two
titles are same) with subsequent details spanning the row.

Thanks very much for any help I could really use it-- Ginger

Get a patched Bash shell with Expat XML parser interface,
http://freshmeat.net/projects/bashdiff/
help xml
help basp

First, parsing of your XML text would go something like

start () {
if [[ ${XML_ELEMENT_STACK[1]} == Programs ]]; then
unset Title Crosscut Pi Institution Project_Summary Start End
fi
}
data () {
case ${XML_ELEMENT_STACK[1]} in
Title|CrossCut|PI|Institution|Project_Summary|Star t|End)
strcat ${XML_ELEMENT_STACK[1]} "$1" ;;
esac
}
end () {
if [[ ${XML_ELEMENT_STACK[1]} == Programs ]]; then
cat <<+ EOF
Title={$Title}
CrossCut={$CrossCut}
PI={$PI}
Institution={$Institution}
Project_Summary={$Project_Summary}
Start={$Start}
End={$End}
EOF
fi
}
xml -s start -d data -e end "`< file.xml`"

You should get

Title={DETECTING AND BLOCKING}
CrossCut={BASE}
PI={John Jones}
Institution={INSTITUTE}
Project_Summary={build an effective}
Start={2004-09-15T00:00:00}
End={2006-09-14T00:00:00}

for the first <Programs>...</Programs> section. Now, if you consider

cat <<+ EOF
...
EOF

as HTML template, with '...' replaced by your table template, then your
solution becomes self-evident. If you have HTML code in a file, then
you can use my BASP (Bash Server Pages) engine.

For that, your template would go something like

<table> ...
<td><% echo -n $Title %></td>
<td><% echo -n $CrossCut %></td>
...
</table>

and you would print it, like

basp "`< template.html`"

--
William Park <op**********@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
Jul 20 '05 #2
William Park <op**********@yahoo.ca> wrote:
start () {
if [[ ${XML_ELEMENT_STACK[1]} == Programs ]]; then
unset Title Crosscut Pi Institution Project_Summary Start End
Typo... should be 'CrossCut' and 'PI'.
fi
}
For that, your template would go something like

<table> ...
<td><% echo -n $Title %></td>
<td><% echo -n $CrossCut %></td>


You can use shortcut, ala ASP,
<td><%=$Title%></td>
...

--
William Park <op**********@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
Jul 20 '05 #3
> The desired effect will be to sorta group by Title (see that two
titles are same) with subsequent details spanning the row.


Hi,

This is an XSLT solution to your problem ,or at least, what I understand
of it.

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:key name="title" match="Title" use="."/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<table>
<xsl:for-each
select="//Title[generate-id(.)=generate-id(key('title',.))]">
<!-- Loop through all titles (no duplicates) -->
<xsl:sort select="current()"/>
<tr>
<th>Title</th>
<th>Crosscut</th>
<th>PI</th>
<th>Institution</th>
<th>Project_Summary</th>
<th>Start</th>
<th>End</th>
</tr>
<xsl:apply-templates select="//Programs[Title= current() ]"/>
</xsl:for-each>
</table>
</body></html>
</xsl:template>

<xsl:template match="Programs">
<tr>
<td><xsl:value-of select="Title"/></td>
<td><xsl:value-of select="CrossCut"/></td>
<td><xsl:value-of select="PI"/></td>
<td><xsl:value-of select="Institution"/></td>
<td><xsl:value-of select="Project_Summary"/></td>
<td><xsl:value-of select="Start"/></td>
<td><xsl:value-of select="End"/></td>
</tr>
</xsl:template>

</xsl:stylesheet>

regards,

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #4
Thanks so much for your reply. This is getting very close!
Unfortunately, it's not quite there. The row headers do not repeat
for each duplicate title, which is good, but the records do repeat.
I am trying to understand your code & which elements are trying to
group the records, but I am new to this & haven't quite figured it
out. Again, thanks very much for posting your code.

"Joris Gillis" <ro**@pandora.be> wrote in message news:<op**************@news.pandora.be>...
The desired effect will be to sorta group by Title (see that two
titles are same) with subsequent details spanning the row.


Hi,

This is an XSLT solution to your problem ,or at least, what I understand
of it.

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:key name="title" match="Title" use="."/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<table>
<xsl:for-each
select="//Title[generate-id(.)=generate-id(key('title',.))]">
<!-- Loop through all titles (no duplicates) -->
<xsl:sort select="current()"/>
<tr>
<th>Title</th>
<th>Crosscut</th>
<th>PI</th>
<th>Institution</th>
<th>Project_Summary</th>
<th>Start</th>
<th>End</th>
</tr>
<xsl:apply-templates select="//Programs[Title= current() ]"/>
</xsl:for-each>
</table>
</body></html>
</xsl:template>

<xsl:template match="Programs">
<tr>
<td><xsl:value-of select="Title"/></td>
<td><xsl:value-of select="CrossCut"/></td>
<td><xsl:value-of select="PI"/></td>
<td><xsl:value-of select="Institution"/></td>
<td><xsl:value-of select="Project_Summary"/></td>
<td><xsl:value-of select="Start"/></td>
<td><xsl:value-of select="End"/></td>
</tr>
</xsl:template>

</xsl:stylesheet>

regards,

Jul 20 '05 #5
Hi,

Perhaps this could get you closer to your goal:

<xsl:key name="title" match="Title" use="."/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<table>
<xsl:for-each select="//Title[generate-id(.)=generate-id(key('title',.))]">
<!-- Loop through all titles (no duplicates) -->
<!-- sort on title -->
<xsl:sort select="current()"/>
<!-- print table headers -->
<tr>
<th>Title</th>
<th>Crosscut</th>
<th>PI</th>
<th>Institution</th>
<th>Project_Summary</th>
<th>Start</th>
<th>End</th>
</tr>
<!-- evaluate all 'Programs' nodes that have a 'Title' child equal to the Title of this iteration of the for-each loop -->
<xsl:apply-templates select="//Programs[Title=current()]"/>
</xsl:for-each>
</table>
</body></html>
</xsl:template>

<xsl:template match="Programs">
<!-- print a new table row and evaluate the children of the 'Programs' node -->
<tr>
<td><xsl:apply-templates select="Title"/></td>
<td><xsl:apply-templates select="CrossCut"/></td>
<td><xsl:apply-templates select="PI"/></td>
<td><xsl:apply-templates select="Institution"/></td>
<td><xsl:apply-templates select="Project_Summary"/></td>
<td><xsl:apply-templates select="Start"/></td>
<td><xsl:apply-templates select="End"/></td>
</tr>
</xsl:template>

<xsl:template match="*">
<!-- select the text value of a node unless it's a duplicate of a previous text value-->
<!-- in other words, only unique text values will be returned-->
<xsl:if test="generate-id(//*[.=current()][../Title = current()/../Title ])=generate-id(.)">
<xsl:value-of select="."/>
</xsl:if>
</xsl:template>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #6
Joris! Thank you. Thank you.

This is great & you've helped me to begin to understand. Many, many thanks,

Ginger
Jul 20 '05 #7

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

Similar topics

2
by: Mark | last post by:
Hi all, This is what I'm trying to do. I'm trying to load a flash movie transparently over my existing html page (not covering the full screen, but 75% of it), so it is kind of similar to a...
21
by: BT | last post by:
I inherited a simple page that needs to be Strict HTML and I'm not very familiar with this standard. What I'm trying to do _should be_ pretty simple so I hope someone can point me in the right...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
2
by: Goober | last post by:
I have the following default.aspx page that works properly. However, what I want to do is to link the graphics within it (that are hard coded now in the default web page) to our corporate...
9
by: Tristán White | last post by:
Hi I am very new to PHP - actually, this is my second day at it, as I've only recently started a new job last week. We're a charity. I have a "No input file selected" problem. A Google search...
4
by: Rabel | last post by:
I am not very good at javascript I mostly am a flash developer but I am trying to apply one of our old expanding menus to work for a new site but it doesn't collapse the way I need it to right now...
1
by: atombee | last post by:
Hi- this is the project that will not end! (sure you've all been there). I had originally purchased a php/css nav bar for the client, but it was buggy as hell, so I decided to do in css, in which I...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
9
by: Chris Ahmsi | last post by:
I have been tasked to create a 'simple' form in Access providing managers to input necessary changes. I have 2 command buttons on the form and a check box. Command button 1 updates my table for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.