Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
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 Search this Thread Display Modes
  #1 (permalink)  
Old June 16th, 2004, 03:11 PM
Registered User
 
Join Date: Jun 2004
Location: Burlington, On, Canada.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default help with xsl templates

hello,
I have a problem. I have an xml file that I am trying to display.

the xml is similar as follows. (The <Zone>'s can come in any order/quantity, and come in 2 types: Those with child <Table>'s, and those without. Zones with Tables always have 'Name="Table"')

<Page>
<Zone Name="Address">
   <Field Name="Address">123 4th st.></Field>
</Zone>
<Zone Name="Table">
   <Table LineNo="1">
      <Field Name="Item">12345</Field>
   </Table>
   <Table LineNo="1">
      <Field Name="Desc">Candy</Field>
   </Table>
   <Table LineNo="2">
      <Field Name="Desc">Cane</Field>
   </Table>
</Zone>
</Page>

I want the output to look something like this:
Address
123 4th St

Item Desc
12345 Candy
         Cane

I have been able to create a template that works for the first address <Zone>, but I do not understand how to create a template that can handle the Table <Zone>. Any help is appreciated.
Reply With Quote
  #2 (permalink)  
Old June 16th, 2004, 06:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To use this you MUST add a line to 'pair' your table:

---> <Table LineNo="2"/>
      <Table LineNo="2">
         <Field Name="Desc">Cane</Field>
      </Table>


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

   <xsl:template match="/">
      <html>
         <head>
            <title></title>
            </head>
            <body>
               <xsl:apply-templates select="Page"/>
           </body>
      </html>
   </xsl:template>

   <xsl:template match="Page"><br/>
      <table border="1">
         <tr><th colspan="2">Address:</th></tr>
            <xsl:for-each select="Zone">
               <tr>
                  <td colspan="2">
                     <xsl:value-of select="Field"/>
                 </td>
              </tr>
           </xsl:for-each>
            <tr><th>Item</th><th>Desc</th></tr>
            <tr>
               <xsl:for-each select="Zone/Table[@LineNo='1']">
                  <td>
                     <xsl:value-of select="Field[@Name='Item']"/><xsl:value-of select="Field[@Name='Desc']"/>
                  </td>
               </xsl:for-each>
            </tr>
            <tr>
               <xsl:for-each select="Zone/Table[@LineNo='2']">
                  <td>
                     <xsl:value-of select="Field[@Name='Item']"/><xsl:value-of select="Field[@Name='Desc']"/>
                  </td>
               </xsl:for-each>
            </tr>
         </table>
   </xsl:template>
</xsl:stylesheet>

However, Im sure it can be done without adding the extra line. I just dont know howto yet ;)
Reply With Quote
  #3 (permalink)  
Old June 16th, 2004, 08:57 PM
Registered User
 
Join Date: Jun 2004
Location: Burlington, On, Canada.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can't thank you enough for your help. Today is my first day working with XSL, and your code helped me a lot. I'm finaly grasping how this works. THANK YOU!!!!
Reply With Quote
  #4 (permalink)  
Old June 17th, 2004, 04:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I should be happy if you're happy. Im not so happy, though. There's a table error when processing additional elements. I just can't figure out how to rearrange/change the code to have the line2 items show below each other. If you find out (if you're going further with your example) please let me know!
Reply With Quote
  #5 (permalink)  
Old June 17th, 2004, 09:30 AM
Registered User
 
Join Date: Jun 2004
Location: Burlington, On, Canada.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You got me on the right track, and opend some doors for me. Considering I spent 6 hours trying to get to that point, I'm thrilled with what you gave me. I am also still having trouble getting line two items to show under the previous lines. I'll be spending the rest of the day trying to get that problem (and some others) licked. I'll post my code if/when I find a solution.
Reply With Quote
  #6 (permalink)  
Old June 23rd, 2004, 07:33 AM
Registered User
 
Join Date: Jun 2004
Location: Dunoon, Argyll, United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

This may be slightly irrelevant, but it opens up a wider issue.

Looking at your source document it seems to me that the structure doesn't look very well designed/thought out.

I think a good point to start from is to consider your data and apply some relational database normalisation rules to the production of the xml itself.

This means you completely understand the data and can get the structure firmly fixed.

I am a newcomer to the whole html/xml/xslt thing so maybe this is way off line...................

Cheers.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
differnce between xsl:apply-templates and xsl:call chandu.mca007 XSLT 2 June 12th, 2007 04:12 AM
HTML formatted text via xsl templates? beckfield XSLT 2 February 26th, 2005 01:48 PM
xsl:apply-templates on Variable containing xml nexus5 XSLT 9 November 4th, 2004 02:55 PM
xsl:apply-templates - Pls help me out imme Avinash XSLT 1 November 13th, 2003 03:18 AM



All times are GMT -4. The time now is 06:54 PM.


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