Hi Guys
Can anyone see what I'm doing wrong here because I'm stumped? I'm trying to teach myself xsl transformations and have been using W3Schools here. I've got a setup that I think should work but I'm not getting any values back when I browse it.
Here's my xsd:-
The xsl file:-
and the xml:-
When I rclick the xml doc and view in browser I see this :-
I'm confident it's finding the xsl because it's showing me the right layout but I'm not seeing any actual values. I've also tried referencing the elements thusly:-
<xsl:value-of select="Person/id" /> which I think should work because I've got the match element set to / which should be the root and Person is the root but I get exactly the same result. What gives?
While I'm about it I've also got a second question. W3Schools refers to creating an xsl file but visual studio adds an xslt file (it doesn't seem to have an option to add an xsl one). I created my xsl by adding an xslt file then dropping the t which seems to work. When I left the t in there it didn't appear to find the xslt at all and just output my value as one long string. That's left me unsure as to whether I'm going about the whole thing correctly though. Should I be leaving it as an xslt file and referring to it differently?
Any help would be welcome.
Can anyone see what I'm doing wrong here because I'm stumped? I'm trying to teach myself xsl transformations and have been using W3Schools here. I've got a setup that I think should work but I'm not getting any values back when I browse it.
Here's my xsd:-
xml Code:
<?xml version="1.0" encoding="utf-8"?> <xs:schema id="Party" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/Ultimate" elementFormDefault="qualified" xmlns="http://tempuri.org/Ultimate Party.xsd"> <xs:element name="Person"> <xs:complexType> <xs:sequence> <xs:element name="id" type="xs:integer"/> <xs:element name="Title"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="5"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="First_Name"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="20"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="Last_Name"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="20"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="Address_1"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="20"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="Address_2"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="20"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="Address_3"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="20"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="Address_4"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="20"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="Postcode"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="20"/> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
The xsl file:-
xsl Code:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2> Customer : <xsl:value-of select="Person/id" /></h2> <table> <tr> <td>Title</td> <td> <xsl:value-of select="Person/Mr"/> </td> </tr> <tr> <td>First Name</td> <td> <xsl:value-of select="Person/First_Name"/> </td> </tr> <tr> <td>Last Name</td> <td> <xsl:value-of select="Person/Last_Name"/> </td> </tr> <tr> <td>Address</td> <td> <xsl:value-of select="Person/Address_1"/> </td> </tr> <tr> <td></td> <td> <xsl:value-of select="Person/Address_2"/> </td> </tr> <tr> <td></td> <td> <xsl:value-of select="Person/Address_3"/> </td> </tr> <tr> <td></td> <td> <xsl:value-of select="Person/Address_4"/> </td> </tr> <tr> <td>Postcode</td> <td> <xsl:value-of select="Person/Postcode"/> </td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet>
and the xml:-
xml Code:
<?xml version="1.0" encoding="utf-8" ?> <?xml-stylesheet type="text/xsl" href="Person.xsl" ?> <Person xmlns="http://tempuri.org/Ultimate" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tempuri.org/Ultimate Party.xsd"> <id>1</id> <Title>Mr</Title> <First_Name>Declan</First_Name> <Last_Name>Hillier</Last_Name> <Address_1>101 Romsey Road</Address_1> <Address_2>Shirley</Address_2> <Address_3>Southampton</Address_3> <Address_4>Hants</Address_4> <Postcode>SO16 4DD</Postcode> </Person>
When I rclick the xml doc and view in browser I see this :-
Code:
Customer :
Title
First Name
Last Name
Address
Postcode
<xsl:value-of select="Person/id" /> which I think should work because I've got the match element set to / which should be the root and Person is the root but I get exactly the same result. What gives?
While I'm about it I've also got a second question. W3Schools refers to creating an xsl file but visual studio adds an xslt file (it doesn't seem to have an option to add an xsl one). I created my xsl by adding an xslt file then dropping the t which seems to work. When I left the t in there it didn't appear to find the xslt at all and just output my value as one long string. That's left me unsure as to whether I'm going about the whole thing correctly though. Should I be leaving it as an xslt file and referring to it differently?
Any help would be welcome.