我无法弄清楚为什么我的代码不能正常工作,我可以获得任何xsl渲染的唯一方法是使用。使用value-of select时的运算符,它只打印出xml的每个值。如果你更改select =&#34的值 - 嘿"只是"。"它会显示一切,但当我试图选择一个特定的元素时,我什么也得不到。
这是我正在使用的代码:
<?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>
&#13;
<?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>
&#13;
答案 0 :(得分:0)
这是使用XSLT报告的#1问题(每天大约一个问题):您的XML位于命名空间中,但您的路径表达式/匹配模式正在查找无命名空间中的元素。