Frustrating Table Creation

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi
Before I start, I am "new" to this, not having had any formal training with xml/xslt, Ive just learnt what I have needed when I need it, so this is going to seem a very easy problem to most of you people, but it is driving me up the wall !
I am having a problem creating a dynamic table, specifically populating the cells. The XML is system generated and changes can be made whenever the users require it, so the table is generated on the fly when the page is loaded.
The column titles and rows (they need sorting - I know) are created from the xml, as these grow when new items are added to the database. I can get the column and row titles from the xml, but I am having the problem in "ticking
the box" to show that the home in the column title has had the box in the row title.
The XML is (shortened) as follows:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Red; standalone<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; yes<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <?<span style="color:#A31515; xml-stylesheet<span style="color:Gray; type="text/xsl Questions.xsl"<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; root<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Table1<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; homeid<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; homeid<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; boxid<span style="color:Blue; >001<span style="color:Blue; </<span style="color:#A31515; boxid<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; datein<span style="color:Blue; >14/02/2011<span style="color:Blue; </<span style="color:#A31515; datein<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; dateout<span style="color:Blue; >14/03/2011<span style="color:Blue; </<span style="color:#A31515; dateout<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; compid<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; compid<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; compname<span style="color:Blue; >Drumconnor NH<span style="color:Blue; </<span style="color:#A31515; compname<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; boxtype<span style="color:Blue; >Bmth<span style="color:Blue; </<span style="color:#A31515; boxtype<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Table1<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Table1<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; homeid<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; homeid<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; boxid<span style="color:Blue; >41<span style="color:Blue; </<span style="color:#A31515; boxid<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; datein<span style="color:Blue; >01/01/1999<span style="color:Blue; </<span style="color:#A31515; datein<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; dateout<span style="color:Blue; >02/01/1999<span style="color:Blue; </<span style="color:#A31515; dateout<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; compid<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; compid<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; compname<span style="color:Blue; >Drumconnor NH<span style="color:Blue; </<span style="color:#A31515; compname<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; boxtype<span style="color:Blue; >Loan<span style="color:Blue; </<span style="color:#A31515; boxtype<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Table1<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Table1<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; homeid<span style="color:Blue; >37<span style="color:Blue; </<span style="color:#A31515; homeid<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; boxid<span style="color:Blue; >77<span style="color:Blue; </<span style="color:#A31515; boxid<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; datein<span style="color:Blue; >01/01/1999<span style="color:Blue; </<span style="color:#A31515; datein<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; dateout<span style="color:Blue; >02/01/1999<span style="color:Blue; </<span style="color:#A31515; dateout<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; compid<span style="color:Blue; >37<span style="color:Blue; </<span style="color:#A31515; compid<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; compname<span style="color:Blue; >Portlet Lodge<span style="color:Blue; </<span style="color:#A31515; compname<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; boxtype<span style="color:Blue; >Loan<span style="color:Blue; </<span style="color:#A31515; boxtype<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Table1<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; root<span style="color:Blue; >
[/code]
And the XSLT:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; xmlns:xsl<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/1999/XSL/Transform<span style="color:Black; "
<span style="color:Red; xmlns:msxsl<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; urn:schemas-microsoft-com:xslt<span style="color:Black; " <span style="color:Red; exclude-result-prefixes<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; msxsl<span style="color:Black; "
<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; rowcount<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; count(root/Table1)<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; currentRow<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; unique-list<span style="color:Black; "
<span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; //compname[not(.=following::compname)]<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; unique-row-list<span style="color:Black; "
<span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; //boxid[not(.=following::boxid)]<span style="color:Black; " <span style="color:Blue; />

<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; thisRow<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; count(root/Table1/homeid)<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; html<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; body<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h2<span style="color:Blue; >Memory Box History<span style="color:Blue; </<span style="color:#A31515; h2<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; border<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr <span style="color:Red; bgcolor<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; #9acd32<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; th<span style="color:Blue; >Box ID<span style="color:Blue; </<span style="color:#A31515; th<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $unique-list<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; th<span style="color:Blue; ><span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; .<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; th<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $unique-row-list<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; curRow<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; .<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; .<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $unique-list<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; curCol<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; .<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; strong<span style="color:Blue; ><span style="color:Green; <!--HERE IS MY PROBLEM-->
<span style="color:Blue; </<span style="color:#A31515; strong<span style="color:Blue; > <span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >

<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; body<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; html<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template<span style="color:Blue; >

<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet<span style="color:Blue; >
[/code]
I know I need to apply another template to fill the TD where I want the check box to appear, but I cannot work out how to compare the column and row titles so that if they match, a "tick" is displayed, and if not, it remains blank.
I also know that some of the vars included are not required, but I can tidy things up once the code does what I need.
Thanks in advance for any help, it will be gratefully accepted (no matter how dumb you think I am) :-)
Neal

View the full article
 
Back
Top