简体   繁体   中英

XSL value-of select isn't working

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> 

这是XSLT在这里报告的#1问题(每天大约一个问题):您的XML在名称空间中,但是您的路径表达式/匹配模式正在没有名称空间中查找元素。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM