【发布时间】:2017-04-27 16:12:46
【问题描述】:
我正在寻求帮助来解决我遇到的 XSLT 样式表问题,我将其应用于基本 XML 文件,该文件将为我们正在构建的门户输出基本 HTML。具体来说,我正在尝试将
示例 XML 源文件:
<?xml version="1.0" encoding="UTF-8"?>
<TitleList>
<book>
<title>Book 1: Part 3. Buying and Selling Stuff</title>
<author>Jon Doe</author>
<PubDate>2010</PubDate>
</book>
<book>
<title>Book 1: Part 7. Making Stuff</title>
<author>Jane Doe</author>
<PubDate>2012</PubDate>
</book>
<book>
<title>Book 1: Part 8. The Art of Creating Things </title>
<author>Jon Doe</author>
<PubDate>2013</PubDate>
</book>
<book>
<title>Book 1: Part 10. Stuff Happens</title>
<author>Jane Doe</author>
<PubDate>2014</PubDate>
</book>
</TitleList>
XSLT 示例:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:output method="html" encoding="UTF-8" />
<xsl:template match="/">
<html>
<head></head>
<body>
<div id="titleList">
<table>
<tr>
<th>Title List</th>
</tr>
<tr>
<xsl:call-template name="retrieveTitles"></xsl:call-template>
</tr>
</table>
</div>
</body>
</html>
</xsl:template>
<xsl:template name="retrieveTitles">
<xsl:for-each select="TitleList/book">
<xsl:sort select="title" />
<tr>
<td>
<xsl:value-of select="title"/>
</td>
<td>
<xsl:value-of select="author" />
</td>
<td>
<xsl:value-of select="PubDate"/>
</td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
标题乱序的结果 HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="titleList">
<table>
<tr>
<th>Title List</th>
</tr>
<tr>
<tr>
<td>Book 1: Part 10. Stuff Happens</td>
<td>Jane Doe</td>
<td>2014</td>
</tr>
<tr>
<td>Book 1: Part 3. Buying and Selling Stuff</td>
<td>Jon Doe</td>
<td>2010</td>
</tr>
<tr>
<td>Book 1: Part 7. Making Stuff</td>
<td>Jane Doe</td>
<td>2012</td>
</tr>
<tr>
<td>Book 1: Part 8. The Art of Creating Things </td>
<td>Jon Doe</td>
<td>2013</td>
</tr>
</tr>
</table>
</div>
</body>
</html>
如何配置 XSLT 脚本的排序元素,以确保在从一位数跳转到两位数时,标题是连续排序的?感谢您的宝贵时间!
问候,
wyattburp86
【问题讨论】: