我想我只是提出了一个新问题,也可以帮助同样寻找解决方案的人。我想从每 3 个项目中添加一个类。
这是我的xml代码
<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"/>
<xsl:if test="not(position() > 10)">
<b><xsl:value-of select="PostDate" /></b> -
<font color='red'><xsl:value-of select="name" /></font>
<p></p>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
只是想要一种简单的方法来插入课程,非常感谢
我想得到
<div clas="item">
2012-07-04 - //3
2012-05-28 - //9
<div class="third"> 2012-05-14 - //8 </div>
2012-03-04 - //1
2012-01-04 - //7
<div class="third"> 2011-12-20 - //11 </div>
2011-11-07 - //12
2011-07-09 - //13
<div class="third">2011-03-04 - //2 </div>
2011-02-25 - //10
</div>