dmannion Posted April 12, 2015 Share Posted April 12, 2015 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> Link to comment Share on other sites More sharing options...
Ingolme Posted April 12, 2015 Share Posted April 12, 2015 <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". Link to comment Share on other sites More sharing options...
dmannion Posted April 13, 2015 Author Share Posted April 13, 2015 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now