0

I can't figure out why my code is not working, the only way i can get any xsl to to render is if i use the . operator when using value-of select which just prints out every value of my xml. If you change the value-of select="hey" to just "." it will show everything but when i try to just select a specific element I get nothing.

This is the code I am working with :

<?xml version="1.0" encoding="UTF-8"?>
<!--
   XML Midterm Project
   New York Knicks

   Author: Nick Johnson
   Date:   3/15/2015

   Filename:         roster.xml
   Supporting File:  roster.xsd
-->



<!-- roster vocabulary -->

<?xml-stylesheet type="text/xsl" href="rosterxsl.xsl"?>
<roster xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://example.com/XMLProject/roster"
    xsi:SchemaLocation="http://example.com/XMLProject roster.xsd">
   <hey>TEST</hey>

    <player lineup="starter">
     <fName>Carmelo</fName>
     <lName>Anthony</lName>
     <age>30</age>
     <number>7</number>
     <position>Foward</position>
     <college>Syracuse</college>
    </player>
  
  <player lineup="reserve">
     <fName>Quincy</fName>
     <lName>Acy</lName>
     <age>24</age>
     <number>4</number>
   <position>Foward</position>
     <college>Baylor</college>
    </player>
  
  <player lineup="reserve">
     <fName>Cole</fName>
     <lName>Aldrich</lName>
     <age>26</age>
     <number>45</number>
   <position>Center</position>
     <college>Kansas</college>
    </player>
  
  <player lineup="reserve">
     <fName>Lou</fName>
     <lName>Amundson</lName>
     <age>32</age>
     <number>21</number>
   <position>Center</position>
     <college>Nevada</college>
    </player>
  
  <player lineup="starter">
     <fName>Andrea</fName>
     <lName>Bargnani</lName>
     <age>29</age>
     <number>77</number>
   <position>Center</position>
     <college>Italy College</college>
    </player>
  
  <player lineup="starter">
     <fName>Jose</fName>
     <lName>Calderon</lName>
     <age>33</age>
     <number>3</number>
   <position>Point Guard</position>
     <college>Spain College</college>
    </player>
  
  <player lineup="reserve">
     <fName>Cleanthony</fName>
     <lName>Early</lName>
     <age>23</age>
     <number>17</number>
      <position>Foward</position>
     <college>Wichita State</college>
    </player>
  
  <player lineup="starter">
     <fName>Langston</fName>
     <lName>Galloway</lName>
     <age>23</age>
     <number>2</number>
   <position>Guard</position>
     <college>St. Joseph's</college>
    </player>
  
  <player lineup="reserve">
     <fName>Tim</fName>
     <lName>Hardaway</lName>
     <age>22</age>
     <number>5</number>
   <position>Guard</position>
     <college>Michigan</college>
    </player>
  
  <player lineup="reserve">
     <fName>Shane</fName>
     <lName>Larkin</lName>
     <age>22</age>
     <number>0</number>
      <position>Point Guard</position>
     <college>Miami</college>
    </player>
  
  <player lineup="reserve">
     <fName>Alexey</fName>
     <lName>Shved</lName>
     <age>26</age>
     <number>1</number>
   <position>Guard</position>
     <college>Russian College</college>
    </player>
  
  <player lineup="starter">
     <fName>Jason</fName>
     <lName>Smith</lName>
     <age>29</age>
     <number>14</number>
   <position>Foward</position>
     <college>Colorado State</college>
    </player>
  
  <player lineup="reserve">
     <fName>Lance</fName>
     <lName>Thomas</lName>
     <age>26</age>
     <number>42</number>
   <position>Foward</position>
     <college>Duke</college>
    </player>
  
  <player lineup="reserve">
     <fName>Travis</fName>
     <lName>Wear</lName>
     <age>24</age>
     <number>6</number>
   <position>Foward</position>
     <college>UCLA</college>
    </player>

   </roster>

<?xml version="1.0" encoding="UTF-8" ?>
<!--
   New Perspectives on XML, 3rd Edition
   Tutorial 6
   Case Problem 1

   Voter Web Style Sheet
   Author: Nick Johnson
   Date:   4/23/2015
   Filename:         teamxsl.xsl
   Supporting Files: 
-->


<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:output method="html"
      doctype-system="about:legacy-compat"
      encoding="UTF-8"
      indent="yes" />
 

   <xsl:template match="/">
      <html>
         <head>
            <title>New York Knicks</title>
            <link href="teamstyle.css" rel="stylesheet" type="text/css" />
         </head>

         <body>
            <div id="header">
               <img src="headerimage.jpg" />
               <p>hey</p>
               <xsl:value-of select="hey" />

            </div>
            <xsl:for-each select="roster/player">
                  <xsl:sort select="fName" />
                  <table>
                     
                     <thead>
                        <tr>
                           <th>First Name</th>
                           <th>Last Name</th>
                           <th>Age</th>
                           <th>Number</th>
                           <th>Position</th>
                           <th>College</th>
                           
                        </tr>
                     </thead>
                     <tbody>
                       <xsl:apply-templates select="roster/player" >
                           
                        </xsl:apply-templates>
                     </tbody>
                  </table>
            </xsl:for-each>
         </body>
      </html>
            
   </xsl:template>

   <xsl:template match="player">
       <tr>
         <td><xsl:value-of select="fName" /></td>
         <td><xsl:value-of select="lName" /></td>
         <td><xsl:value-of select="age"/></td>
         <td><xsl:value-of select="position" /></td>
         <td><xsl:value-of select="number" /></td>
         <td><xsl:value-of select="college" /></td>
         
      </tr>
   </xsl:template>



  
 

</xsl:stylesheet>
Nick
  • 5
  • 2
  • @Michael Kay said it all. See [XSLT with XML source that has a default namespace set to xmlns](http://stackoverflow.com/questions/1344158/xslt-with-xml-source-that-has-a-default-namespace-set-to-xmlns), for example. This is also worth reading : http://www.jenitennison.com/2007/07/01/the-perils-of-default-namespaces.html – potame Apr 24 '15 at 07:53

1 Answers1

0

It's the #1 problem reported here with XSLT (about one question a day): your XML is in a namespace, but your path expressions / match patterns are looking for elements in no namespace.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164