我正在学习 XML 和 XSLT,我有两部分代码,一个是 XML,另一个是 XSLT,
这是我的 XML 文件
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xslt.xslt"?>
<groups>
<elements>
<name>//1</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2012-03-04</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//2</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2011-03-04</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//3</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2012-07-04</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//4</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2009-01-04</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//5</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2009-02-04</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//6</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2008-06-04</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//7</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2012-01-04</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//8</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2012-05-14</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//9</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2012-05-28</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//10</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2011-02-25</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//11</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2011-12-20</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//12</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2011-11-07</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//13</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2011-07-09</PostDate>
<trackno></trackno>
</elements>
<elements>
<name>//14</name>
<BOD></BOD>
<description/>
<URL></URL>
<Hobbbies>
<Sport></Sport>
<Music></Music>
</Hobbbies>
<Height></Height>
<PostDate>2005-10-19</PostDate>
<trackno></trackno>
</elements>
</groups>
这是我的 XSLT 代码
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Try to display only 9 or 12</h2>
<xsl:for-each select="/groups/elements">
<xsl:sort select="PostDate" order="descending"/>
<b><xsl:value-of select="PostDate" /></b> -
<font color='red'><xsl:value-of select="name" /></font>
<p></p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我的问题是如何将项目编号限制为仅显示 12 个并使它们显示在页面上 3 个项目或每行 4 个项目?
我发现有人使用位置,只是不知道要达到哪个位置来限制数字并制作行?
您可以在此处复制并粘贴我的代码以查看输出http://markbucayan.appspot.com/xslt/index.html
非常感谢任何建议和解决方案