Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old July 6th, 2006, 10:04 AM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 (&nbsp;).

Any help?


 
Old July 6th, 2006, 10:24 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old July 6th, 2006, 02:36 PM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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




 
Old July 6th, 2006, 03:07 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old July 7th, 2006, 02:21 AM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<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>&nbsp;</td>
                      <td>l2c3</td>
                    </tr>
                    <tr>
                      <td>l3c1</td>
                      <td>l3c2</td>
                      <td>&nbsp;</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!

 
Old July 7th, 2006, 02:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old July 10th, 2006, 03:31 AM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Implement HTML elements in my template with Zend snowbydave1 PHP How-To 0 October 25th, 2008 02:00 AM
Remove orphaned html elements from html string pauliehaha C# 2008 aka C# 3.0 2 June 30th, 2008 09:40 AM
display out of order html elements? chobo XSLT 2 April 1st, 2008 02:28 AM
Using xml elements as html attributes chipmaster XSLT 4 June 26th, 2007 10:22 AM
Conditionally displaying html elements in xslt dharni XSLT 1 August 14th, 2005 04:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.