Html XML XSL XSL:sort未对文件进行排序
我试图按日期或位置对这个简单的表进行排序,但似乎没有任何效果。似乎根本没有应用排序。我在w3c和论坛等网站上搜索了一些技巧,但我无法让它工作 以下是我的XML代码:Html XML XSL XSL:sort未对文件进行排序,html,xml,xslt,Html,Xml,Xslt,我试图按日期或位置对这个简单的表进行排序,但似乎没有任何效果。似乎根本没有应用排序。我在w3c和论坛等网站上搜索了一些技巧,但我无法让它工作 以下是我的XML代码: <?xml version="1.0" encoding="utf-8" ?> <?xml-stylesheet href="travelDiaries.xsl" type="text/xsl"?> <diaries> <diary name='Wojciech'>
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="travelDiaries.xsl" type="text/xsl"?>
<diaries>
<diary name='Wojciech'>
<entry date='2020/06/12' title='Poland'>
<location>Poland</location>
<description>Trip to see the, family and friends in a home town</description>
<img></img>
</entry>
</diary>
<diary name='Karolina'>
<entry date='2018/04/12' title='Poland'>
<location>Poland</location>
<description>Trip for site visiting, visiting a Capital city of Poland - Warsaw </description>
<img></img>
</entry>
</diary>
<diary name='Kuba'>
<entry date='2019/03/02' title='Czech republic'>
<location>Czech republic</location>
<description>Visiting the Old Praque with friends, seeing most popular sites</description>
<img></img>
</entry>
</diary>
<diary name='Kevin'>
<entry date='2020/11/08' title='Usa'>
<location>Usa</location>
<description>Traveling around different states, meeting people and learning about the culture</description>
<img></img>
</entry>
</diary>
</diaries>
波兰
参观家乡的家庭、家人和朋友
我真的觉得被这一个卡住了。您对每一个
都使用了一个xsl:for-each
太多了。
只需将XSLT-1.0代码缩减为
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/diaries">
<html>
<body>
<table border="5">
<tr bgcolor="lawngreen">
<th>Date</th>
<th>Location</th>
<th>Description</th>
<th>Image</th>
</tr>
<xsl:for-each select="diary">
<xsl:for-each select="entry">
<xsl:sort select="entry/@date"/>
<tr>
<td>
<xsl:value-of select="@date"/>
</td>
<td>
<xsl:value-of select="location"/>
</td>
<td>
<xsl:value-of select="description"/>
</td>
<td>
<img border="1" width="100px" height="100px">
<xsl:attribute name="src">
<xsl:value-of select="img"/>
</xsl:attribute>
</img>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
日期
位置
描述
形象
…您的输出将按@日期
和位置
排序,您正在执行:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/diaries">
<html>
<body>
<table border="5">
<tr bgcolor="lawngreen">
<th>Date</th>
<th>Location</th>
<th>Description</th>
<th>Image</th>
</tr>
<xsl:for-each select="diary">
<xsl:sort select="entry/@date"/>
<xsl:sort select="entry/location"/>
<tr>
<td>
<xsl:value-of select="entry/@date"/>
</td>
<td>
<xsl:value-of select="entry/location"/>
</td>
<td>
<xsl:value-of select="entry/description"/>
</td>
<td>
<img border="1" width="100px" height="100px">
<xsl:attribute name="src">
<xsl:value-of select="entry/img"/>
</xsl:attribute>
</img>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
@Cahirsu-您可以尝试使用这种方式进行多重排序:
<xsl:for-each select="diary/entry">
<xsl:sort select="@date"/>
**
**
并应用变量$pr我已经尝试过这个解决方案,但它不起作用。不显示该表的内容。谢谢你的努力。
<xsl:for-each select="diary/entry">
<xsl:sort select="@date"/>
<xsl:template match="/">
<xsl:variable name="pr">
**<xsl:perform-sort select="entry">
<xsl:sort select="@date" data-type="number" order="descending"/>
<xsl:sort select="location" order="ascending"/>
</xsl:perform-sort>**
</xsl:variable>
</xsl:template>