Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 6th, 2006, 10:04 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
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?


Reply With Quote
  #2 (permalink)  
Old July 6th, 2006, 10:24 AM
mhkay's Avatar
Wrox Author
Points: 18,392, Level: 59
Points: 18,392, Level: 59 Points: 18,392, Level: 59 Points: 18,392, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,947
Thanks: 0
Thanked 288 Times in 283 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
Reply With Quote
  #3 (permalink)  
Old July 6th, 2006, 02:36 PM
Registered User
 
Join Date: Jun 2006
Location: , , .
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




Reply With Quote
  #4 (permalink)  
Old July 6th, 2006, 03:07 PM
mhkay's Avatar
Wrox Author
Points: 18,392, Level: 59
Points: 18,392, Level: 59 Points: 18,392, Level: 59 Points: 18,392, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,947
Thanks: 0
Thanked 288 Times in 283 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
Reply With Quote
  #5 (permalink)  
Old July 7th, 2006, 02:21 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
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!

Reply With Quote
  #6 (permalink)  
Old July 7th, 2006, 02:55 AM
mhkay's Avatar
Wrox Author
Points: 18,392, Level: 59
Points: 18,392, Level: 59 Points: 18,392, Level: 59 Points: 18,392, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,947
Thanks: 0
Thanked 288 Times in 283 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
Reply With Quote
  #7 (permalink)  
Old July 10th, 2006, 03:31 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
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!!

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 02:17 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.