我的XML就在这里,它实际上大约有300个电影元素,但这只是为了给你一个感觉 -
<mediaList>
<movie id="1325947" dateCreated="2014-04-23">
<title>Gator</title>
<director>Burt Reynolds</director>
<genre>Action</genre>
<writer>William W. Norton</writer>
<language>English</language>
<year>1976</year>
<callNumber href="http://endeavor.flo.org/vwebv/holdingsInfo?bibId=1325947">[DVD] PN1995.9 .A3 R49 2003</callNumber>
<coverArt href="Pics/Gator.jpg"/>
</movie>
<movie id="1094761" dateCreated="2014-04-23">
<title>Assault on Precinct 13</title>
<director>Jean-François Richet</director>
<genre>Action</genre>
<genre>Police</genre>
<writer>James DeMonaco</writer>
<language>English</language>
<year>2005</year>
<callNumber href="http://endeavor.flo.org/vwebv/holdingsInfo?bibId=1094761">[DVD] PN1995.9 .A3 R53 2005</callNumber>
<coverArt href="Pics/AssaultonPrecinct13.jpg"/>
</movie>
<movie id="716486" dateCreated="2014-04-23">
<title>Thunder Road</title>
<director>Arthur Ripley</director>
<genre>Action</genre>
<genre>Crime</genre>
<writer>James Atlee Phillips</writer>
<writer>Walter Wise</writer>
<language>English</language>
<year>1958</year>
<callNumber href="http://endeavor.flo.org/vwebv/holdingsInfo?bibId=716486">[DVD] PN1995.9 .A3 R57 2000</callNumber>
<coverArt href="Pics/ThunderRoad.jpg"/>
</movie>
<movie id="1335109" dateCreated="2014-04-23">
<title>From Dusk Till Dawn</title>
<director>Robert Rodriguez</director>
<genre>Action</genre>
<genre>Vampire</genre>
<writer>Quentin Tarantino</writer>
<screenplay href="http://endeavor.flo.org/vwebv/holdingsInfo?bibId=527135">PN1997 .F7466 T37 1995</screenplay>
<language>English</language>
<year>1998</year>
<callNumber href="http://endeavor.flo.org/vwebv/holdingsInfo?bibId=1335109">[DVD] PN1995.9 .A3 R63 1998</callNumber>
<coverArt href="Pics/FromDuskTillDawn.jpg"/>
</movie>
</mediaList>
我有几种不同的样式表我正在使用它,其中一个旨在将它们转换为漂亮漂亮的图片和标题布局。那个样式表在这里:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" indent="yes"/>
<xsl:key name="genre" match="genre" use="."/>
<xsl:param name="groupBy" select="'genre'"/>
<xsl:template match="/*">
<html>
<head>
<link rel="stylesheet" type="text/css" href="mediaList.css"/>
</head>
<body>
<xsl:apply-templates
select="movie//*[local-name() = $groupBy][generate-id() = generate-id(key($groupBy, .)[1])]" mode="toc">
<xsl:sort order="ascending"/>
</xsl:apply-templates>
<xsl:apply-templates
select="movie//*[local-name() = $groupBy][generate-id() = generate-id(key($groupBy, .)[1])]" mode="contents">
<xsl:sort order="ascending"/>
<xsl:sort select="title"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="movie//*" mode="contents">
<h1>
<a>
<xsl:attribute name="id">
<xsl:value-of select="."/>
</xsl:attribute>
</a>
<xsl:value-of select="."/>
</h1>
<table class="genre">
<tr>
<xsl:apply-templates select="key($groupBy, .)/ancestor::movie">
<xsl:sort select="title"/>
</xsl:apply-templates>
</tr>
</table>
</xsl:template>
<xsl:template match="movie">
<td class="genre">
<div class="image">
<div class="trick"/>
<img>
<xsl:attribute name="src">
<xsl:value-of select="coverArt/@href"/>
</xsl:attribute>
<xsl:attribute name="alt">Movie poster for '<xsl:value-of select="title"/>'
</xsl:attribute>
</img>
</div>
<br/>
<a>
<xsl:attribute name="href">
<xsl:value-of select="callNumber/@href"/>
</xsl:attribute>
<xsl:value-of select="title"/>
</a>
</td>
</xsl:template>
<xsl:template match="movie//*" mode="toc">
<a>
<xsl:attribute name="href">#<xsl:value-of select="."/>
</xsl:attribute>
<xsl:value-of select="."/>
</a>
<br/>
</xsl:template>
</stylesheet>
我遇到的问题是,目前每个类型在其表格中都有一行,并且需要大量滚动来查看所有电影 - 我想要一种强制限制的方式,比如7或10每 所以每个类型都包含在一个表中,但每行固定数量的单元格
有什么想法? XSLT 1.0或2.0解决方案将非常有必要
答案 0 :(得分:0)
您可以使用subsequence()
返回所需数量的电影(td
元素)。
尝试更改此模板:
<xsl:template match="movie//*" mode="contents">
<h1>
<a>
<xsl:attribute name="id">
<xsl:value-of select="."/>
</xsl:attribute>
</a>
<xsl:value-of select="."/>
</h1>
<table class="genre">
<tr>
<xsl:apply-templates select="key($groupBy, .)/ancestor::movie">
<xsl:sort select="title"/>
</xsl:apply-templates>
</tr>
</table>
</xsl:template>
到这个模板:
<xsl:template match="movie//*" mode="contents">
<h1>
<!--Used attribute value template to cleanup code.-->
<a id="{.}"/>
<xsl:value-of select="."/>
</h1>
<table class="genre">
<tr>
<!--Wrapped xsl:apply-templates in xsl:variable.-->
<xsl:variable name="movies">
<xsl:apply-templates select="key($groupBy, .)/ancestor::movie">
<xsl:sort select="title"/>
</xsl:apply-templates>
</xsl:variable>
<!--Output the 1st through 10th td's stored in $movies.-->
<xsl:copy-of select="subsequence($movies/td,1,10)"/>
</tr>
</table>
</xsl:template>