Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27240

xsl transformations - Why isn't value-of finding anything

$
0
0
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:-
xml Code:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xs:schema id="Party"
  3.     xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4.     targetNamespace="http://tempuri.org/Ultimate"
  5.     elementFormDefault="qualified"
  6.     xmlns="http://tempuri.org/Ultimate Party.xsd">
  7.  
  8.   <xs:element name="Person">
  9.     <xs:complexType>
  10.       <xs:sequence>
  11.         <xs:element name="id" type="xs:integer"/>
  12.         <xs:element name="Title">
  13.           <xs:simpleType>
  14.             <xs:restriction base="xs:string">
  15.               <xs:maxLength value="5"/>
  16.             </xs:restriction>
  17.           </xs:simpleType>
  18.         </xs:element>
  19.         <xs:element name="First_Name">
  20.           <xs:simpleType>
  21.             <xs:restriction base="xs:string">
  22.               <xs:maxLength value="20"/>
  23.             </xs:restriction>
  24.           </xs:simpleType>
  25.         </xs:element>
  26.         <xs:element name="Last_Name">
  27.           <xs:simpleType>
  28.             <xs:restriction base="xs:string">
  29.               <xs:maxLength value="20"/>
  30.             </xs:restriction>
  31.           </xs:simpleType>
  32.         </xs:element>
  33.         <xs:element name="Address_1">
  34.           <xs:simpleType>
  35.             <xs:restriction base="xs:string">
  36.               <xs:maxLength value="20"/>
  37.             </xs:restriction>
  38.           </xs:simpleType>
  39.         </xs:element>
  40.         <xs:element name="Address_2">
  41.           <xs:simpleType>
  42.             <xs:restriction base="xs:string">
  43.               <xs:maxLength value="20"/>
  44.             </xs:restriction>
  45.           </xs:simpleType>
  46.         </xs:element>
  47.         <xs:element name="Address_3">
  48.           <xs:simpleType>
  49.             <xs:restriction base="xs:string">
  50.               <xs:maxLength value="20"/>
  51.             </xs:restriction>
  52.           </xs:simpleType>
  53.         </xs:element>
  54.         <xs:element name="Address_4">
  55.           <xs:simpleType>
  56.             <xs:restriction base="xs:string">
  57.               <xs:maxLength value="20"/>
  58.             </xs:restriction>
  59.           </xs:simpleType>
  60.         </xs:element>
  61.         <xs:element name="Postcode">
  62.           <xs:simpleType>
  63.             <xs:restriction base="xs:string">
  64.               <xs:maxLength value="20"/>
  65.             </xs:restriction>
  66.           </xs:simpleType>
  67.         </xs:element>
  68.       </xs:sequence>
  69.     </xs:complexType>
  70.   </xs:element>
  71. </xs:schema>

The xsl file:-
xsl Code:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet version="1.0"
  3.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.  
  5.     <xsl:template match="/">
  6.       <html>
  7.         <body>
  8.           <h2> Customer : <xsl:value-of select="Person/id" /></h2>
  9.           <table>
  10.             <tr>
  11.               <td>Title</td>
  12.               <td>
  13.                 <xsl:value-of select="Person/Mr"/>
  14.               </td>
  15.             </tr>
  16.             <tr>
  17.               <td>First Name</td>
  18.               <td>
  19.                 <xsl:value-of select="Person/First_Name"/>
  20.               </td>
  21.             </tr>
  22.             <tr>
  23.               <td>Last Name</td>
  24.               <td>
  25.                 <xsl:value-of select="Person/Last_Name"/>
  26.               </td>
  27.             </tr>
  28.             <tr>
  29.               <td>Address</td>
  30.               <td>
  31.                 <xsl:value-of select="Person/Address_1"/>
  32.               </td>
  33.             </tr>
  34.             <tr>
  35.               <td></td>
  36.               <td>
  37.                 <xsl:value-of select="Person/Address_2"/>
  38.               </td>
  39.             </tr>
  40.             <tr>
  41.               <td></td>
  42.               <td>
  43.                 <xsl:value-of select="Person/Address_3"/>
  44.               </td>
  45.             </tr>
  46.             <tr>
  47.               <td></td>
  48.               <td>
  49.                 <xsl:value-of select="Person/Address_4"/>
  50.               </td>
  51.             </tr>
  52.             <tr>
  53.               <td>Postcode</td>
  54.               <td>
  55.                 <xsl:value-of select="Person/Postcode"/>
  56.               </td>
  57.             </tr>
  58.           </table>
  59.         </body>
  60.       </html>
  61.     </xsl:template>
  62. </xsl:stylesheet>

and the xml:-
xml Code:
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <?xml-stylesheet type="text/xsl" href="Person.xsl" ?>
  3. <Person
  4.   xmlns="http://tempuri.org/Ultimate"
  5.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6.   xsi:schemaLocation="http://tempuri.org/Ultimate Party.xsd">
  7.  
  8.   <id>1</id>
  9.   <Title>Mr</Title>
  10.   <First_Name>Declan</First_Name>
  11.   <Last_Name>Hillier</Last_Name>
  12.   <Address_1>101 Romsey Road</Address_1>
  13.   <Address_2>Shirley</Address_2>
  14.   <Address_3>Southampton</Address_3>
  15.   <Address_4>Hants</Address_4>
  16.   <Postcode>SO16 4DD</Postcode>
  17. </Person>

When I rclick the xml doc and view in browser I see this :-
Code:

Customer :

Title 
First Name 
Last Name 
Address 
 
 
 
Postcode

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.

Viewing all articles
Browse latest Browse all 27240

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>