Jump to content
Sign in to follow this  
dmannion

XML output on XSL with table

Recommended Posts

I would like to have my stylesheet use an XML output and if possible use it with a table. I seem to only get this to work with a HTML output not a XML output. I am fairly new at XML so any examples of how to do this or suggestions would be greatly appreciated.

 

Here is my XML code

 

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="Lesson_8_obj_1.xsl" type="text/xsl"?><!DOCTYPE Employees><Employees xmlns:xsi="http://www.w3.org/20...Schema-instance"xsi:noNamespaceSchemaLocation="xsd.xsd">> <Employee> <First>John</First> <Last>Smith</Last> <Phone Type="Home">1-800-123-4567</Phone> <Birthday>1960-05-25</Birthday> <HourlyRate>35.85</HourlyRate></Employee> <Employee> <First>Jane</First> <Last>Jones</Last> <Phone Type="Cell">1-800-999-9999</Phone> <Birthday>1980-11-01</Birthday> <HourlyRate>58.17</HourlyRate></Employee></Employees>

 

Here is my XSL code.

 

 

<?xml version="1.0" ?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" indent="yes"/>

<xsl:template match="/"><table> <tr> <th>First</th> <th>Last</th> <th>Phone</th> <th>Birthday</th> <th>HourlyRate</th> </tr><xsl:for-each select="Employees/Employee"> <tr> <td><xsl:value-of select="First"/></td> <td><xsl:value-of select="Last"/></td> <td><xsl:value-of select="Phone"/></td> <td><xsl:value-of select="Birthday"/></td> <td><xsl:value-of select="HourlyRate"/></td></tr></xsl:for-each> </table> </xsl:template></xsl:stylesheet>

Share this post


Link to post
Share on other sites

<table> is an HTML thing. You can't write an XML file with a <table> element and expect it to render a table visually because in XML, <table> doesn't have any special meaning, it's just an element named "table".

Share this post


Link to post
Share on other sites

Thank you for the quick reply and information. Now that I know this I am playing with it and I can get output xml and text to work but it comes out as one line.

 

> John Smith 1-800-123-4567 1960-05-25 35.85 Jane Jones 1-800-999-9999 1980-11-01 58.17

 

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" indent="yes"/><xsl:template match="/Employee"> <Employee> <FirstName><xsl:value-of select="First" /></FirstName> <LastName><xsl:value-of select="Last" /></LastName> <Phone><xsl:value-of select="Phone" /></Phone> <Birthday><xsl:value-of select="Birthday" /></Birthday> <HourlyRate><xsl:value-of select="HourlyRate" /></HourlyRate> </Employee></xsl:template></xsl:stylesheet>

 

With an output method being XML can you have each Employee be a separate line without using HTML table?

 

Thank you

Don

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...