473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How does one add a second table to an XML file using XSL Style Sheet?

17
I’m very new to XML and I’ve encountered my first problem. I’m trying to figure out how to display a second table in my XML output. Currently I’ve created an .xsl Style Sheet which generates one table when opened with XML.

How does one get a second table to show up? At this point I really don’t care if it’s the same exact table as long as I can see two tables and not one. An example of a second table would show COUNTRY, COMPANY, PRICE, and YEAR. I know how to display this information in one table but I want to break it up int two tables.

***I've attached a picture on what I would like the XML file to look like.***

Below are my XML and XSLT files.

[U]XML File: [/u]

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <?xml-stylesheet type="text/xsl" href="test.xsl"?>
  3. <catalog>
  4.     <cd>
  5.         <title>All my eX's live in Texas</title>
  6.         <artist>George Strait</artist>
  7.         <country>Russia</country>
  8.         <company>NCS</company>
  9.         <price>100.00</price>
  10.         <year>1984</year>
  11.     </cd>
  12.     <cd>
  13.         <title>Hide your heart</title>
  14.         <artist>Bonnie Tyler</artist>
  15.         <country>UK</country>
  16.         <company>CBS Records</company>
  17.         <price>9.90</price>
  18.         <year>1988</year>
  19.     </cd>
  20.     <cd>
  21.         <title>Greatest Hits</title>
  22.         <artist>Dolly Parton</artist>
  23.         <country>USA</country>
  24.         <company>RCA</company>
  25.         <price>9.90</price>
  26.         <year>1982</year>
  27.     </cd>
  28.     <cd>
  29.         <title>Still got the blues</title>
  30.         <artist>Gary Moore</artist>
  31.         <country>UK</country>
  32.         <company>Virgin records</company>
  33.         <price>10.20</price>
  34.         <year>1990</year>
  35.     </cd>
  36.     <cd>
  37.         <title>Eros</title>
  38.         <artist>Eros Ramazzotti</artist>
  39.         <country>EU</country>
  40.         <company>BMG</company>
  41.         <price>9.90</price>
  42.         <year>1997</year>
  43.     </cd>
  44.     <cd>
  45.         <title>One night only</title>
  46.         <artist>Bee Gees</artist>
  47.         <country>UK</country>
  48.         <company>Polydor</company>
  49.         <price>10.90</price>
  50.         <year>1998</year>
  51.     </cd>
  52.  
  53. </catalog>
[U]XSLT File: [/u]

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:template match="/"> 
  4.   <html>
  5.   <body>
  6.   <h2>My CD Collection</h2>
  7.     <table border="1">
  8.       <tr bgcolor="red">
  9.         <th>Title</th>
  10.         <th>Artist</th>
  11.       </tr>
  12.       <xsl:for-each select="catalog/cd">
  13.       <tr>
  14.         <td><xsl:value-of select="title"/></td>
  15.         <td><xsl:value-of select="artist"/></td>
  16.       </tr>
  17.       </xsl:for-each>
  18.     </table>
  19.   </body>
  20.   </html>
  21. </xsl:template>
  22. </xsl:stylesheet>
Thank You,

Gabe
Attached Images
File Type: jpg exampleoutput.jpg (12.0 KB, 166 views)
Mar 29 '10 #1

✓ answered by Dormilich

(didn’t apply any changes)
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:template match="/"> 
  4.   <html>
  5.   <body>
  6.   <h2>My CD Collection</h2>
  7.     <table border="1">
  8.       <tr bgcolor="red">
  9.         <th>Title</th>
  10.         <th>Artist</th>
  11.       </tr>
  12.       <xsl:for-each select="catalog/cd">
  13.       <tr>
  14.         <td><xsl:value-of select="title"/></td>
  15.         <td><xsl:value-of select="artist"/></td>
  16.       </tr>
  17.       </xsl:for-each>
  18.     </table>
  19.  
  20.     <table border="1">
  21.       <tr bgcolor="red">
  22.         <th>Title</th>
  23.         <th>Artist</th>
  24.       </tr>
  25.       <xsl:for-each select="catalog/cd">
  26.       <tr>
  27.         <td><xsl:value-of select="title"/></td>
  28.         <td><xsl:value-of select="artist"/></td>
  29.       </tr>
  30.       </xsl:for-each>
  31.     </table>
  32.   </body>
  33.   </html>
  34. </xsl:template>
  35. </xsl:stylesheet>

4 2024
Dormilich
8,658 Expert Mod 8TB
um, repeat the part where you create the table?
Mar 30 '10 #2
GabeGGG
17
Thanks Dormilich but can you please elaborate? Sorry, I’m new to this whole thing.
Mar 30 '10 #3
Dormilich
8,658 Expert Mod 8TB
(didn’t apply any changes)
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:template match="/"> 
  4.   <html>
  5.   <body>
  6.   <h2>My CD Collection</h2>
  7.     <table border="1">
  8.       <tr bgcolor="red">
  9.         <th>Title</th>
  10.         <th>Artist</th>
  11.       </tr>
  12.       <xsl:for-each select="catalog/cd">
  13.       <tr>
  14.         <td><xsl:value-of select="title"/></td>
  15.         <td><xsl:value-of select="artist"/></td>
  16.       </tr>
  17.       </xsl:for-each>
  18.     </table>
  19.  
  20.     <table border="1">
  21.       <tr bgcolor="red">
  22.         <th>Title</th>
  23.         <th>Artist</th>
  24.       </tr>
  25.       <xsl:for-each select="catalog/cd">
  26.       <tr>
  27.         <td><xsl:value-of select="title"/></td>
  28.         <td><xsl:value-of select="artist"/></td>
  29.       </tr>
  30.       </xsl:for-each>
  31.     </table>
  32.   </body>
  33.   </html>
  34. </xsl:template>
  35. </xsl:stylesheet>
Mar 30 '10 #4
GabeGGG
17
Dormilich I owe you a case of beer. Thank you very much for looking into this for me.

Gabe
Mar 30 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mark | last post by:
Hi - I want to allow users of an intranet application, to select their own colours etc. So I have a tbale in my database, which has fields called bgcolour, fontcolour etc. As I want all pages...
1
by: Utada P.W. SIU | last post by:
Dear All, I would like to using style sheet in ASP generated Excel, but it sees cannot using it. Here's my code: '------------------- CODE ----------------------------------------- <style>...
19
by: Roger | last post by:
How can I pass parameters to a style sheet? I have noticed a couple of sites are now passing variables to the style sheet, which appear to be substituted at run time. For example: <link...
1
by: Selden McCabe | last post by:
I'm trying to use a style sheet and am missing something. In one project the following procedure works, and in another it won't: 1. Create a new Webform 2. Drag Styles.css to the Webform's...
2
by: Matthew McDermott | last post by:
Hi, I am working on "reskinning" an application that uses style sheets. I have been editing the default stylesheets by adding my alterations to the bottom of the .css files. I was wondering...
2
by: Kenneth P | last post by:
Hi, I'm developing asp.net (vb) apps in VS.NET 2003, and I'd like to know how you can write style sheet code in a sub in an .aspx page that when it's rendered as html/text/css code in the .aspx...
8
by: JT | last post by:
Hi, I have done a fair amount of style editing inline in ASP. I'm now using VS 2005 with a standard web project (not Web Application Project). This is my first foray into CSS in a style sheet...
7
by: moro145 | last post by:
Hi I deleted my massenger history files xml and i could recover them full size but when i open then i get this error massage : The XML page cannot be displayed Cannot view XML input using...
1
by: moro145 | last post by:
Hi I deleted my massenger history files xml and i could recover them full size but when i open then i get this error massage : The XML page cannot be displayed Cannot view XML input using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.