 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 6th, 2006, 10:04 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
HTML table with missing values (elements)
Hi,
I've a structure like that:
<ProgTools>
<ProgTool>
<Keyword>
<Characteristic>PROGNAME</Characteristic>
<ValueDescription>bla1</ValueDescription>
</Keyword>
<Keyword>
<Characteristic>PROGTYPE</Characteristic>
<ValueDescription>bla2</ValueDescription>
</Keyword>
...
NOT all the keywords will be given.
A record ProgTool may contain cell 1, 2, 3.
The 2nd rec. may contain only 1 and 3.
Another may contain 2 and 3 etc.
The table should be written with <tr> and <td>, empty fields with a space inside ( ).
Any help?
|
|

July 6th, 2006, 10:24 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
If you always want characteristic S in column 1, W in column 2, and H in column 3, then do
<tr>
<td>
<xsl:value-of select="Keyword[Characteristic='S']/ValueDescription"/>
</td>
<td>
<xsl:value-of select="Keyword[Characteristic='W']/ValueDescription"/>
</td>
<td>
<xsl:value-of select="Keyword[Characteristic='H']/ValueDescription"/>
</td>
</tr>
If that's not what you want, then you'll have to explain it better.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

July 6th, 2006, 02:36 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Michael,
I try to explain better, sorry for my bad english ;)
I have a XML structure looking like a 'incomplete' 2-dimensional matrix.
l = line, c = column
l1c1, l1c2, l1c3
----, l2c2, l2c2
l3c1, ----, l3c3
l4c1, l4c2, ----
As you see, not all elements of the 'matrix' are given by the XML, just the lNcN values (N=1...n).
I'm now looking for a XSL programming algorithm, which displays all the given elements by its values BUT also displays the '----' values as empty HTM table cells (<td></td>).
I'm using the lastest Saxon engine shipped with Stylus Studio.
Is that any clearer?
Ciao
|
|

July 6th, 2006, 03:07 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Please try to show what the input XML looks like, and how this relates to the desired output.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

July 7th, 2006, 02:21 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<ProgTools>
<ProgTool>
<Keyword>
<Characteristic>PROGNAME</Characteristic>
<ValueDescription>l1c1</ValueDescription>
</Keyword>
<Keyword>
<Characteristic>PROGTYPE</Characteristic>
<ValueDescription>l1c2</ValueDescription>
</Keyword>
<Keyword>
<Characteristic>PROGADAPTER</Characteristic>
<ValueDescription>l1c3</ValueDescription>
</Keyword>
...
INPUT:
ProgTools has n ProgTool elements (lines).
Each ProgTool has 1 to n Keywords/Characteristics.
OUTPUT (HTM):
<table>
<tr>
<td>l1c1</td>
<td>l1c2</td>
<td>l1c3</td>
</tr>
<tr>
<td>l2c1</td>
<td> </td>
<td>l2c3</td>
</tr>
<tr>
<td>l3c1</td>
<td>l3c2</td>
<td> </td>
</tr>
</table>
As you see from the output, not ALL the fields of one 'record' will have to be filled, so the algorithm should be able to handle 'incomplete' records.
Thanks for your help!
|
|

July 7th, 2006, 02:55 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Why can't you do what I ask?
You haven't shown me the data that produces the second and third rows of your table.
If they look like I think they look, then the code I gave you before works. If that code doesn't work, then it must be because I made a wrong guess about your input. That's why I asked you to show me the input.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

July 10th, 2006, 03:31 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Michael,
your solution:
<tr>
<td>
<xsl:value-of select="Keyword[Characteristic='S']/ValueDescription"/>
</td>
<td>
<xsl:value-of select="Keyword[Characteristic='W']/ValueDescription"/>
</td>
<td>
<xsl:value-of select="Keyword[Characteristic='H']/ValueDescription"/>
</td>
</tr>
worked! Thank you!!
|
|
 |