我想創建一個列出電影的XSLT,並且我正在設置標題的樣式,以便每個標題都有自己的顏色,然後使用插值選擇標題(XPath ?)CSS空間的名稱和麻煩XSLT
下面是XSL文件:
<?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>
<head>
<title>Videos</title>
<style>
table, tr, td { border: thin black solid }
th { background-color: #AAFFAA }
.Daredevil { color: red; }
/* Look at those spaces! Hrmphf! */
.Drag Me To Hell { color: green; }
</style>
</head>
<body>
<table>
<tr><th>Movies</th></tr>
<xsl:apply-templates select="//movie"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="//movie[not(@title=preceding::movie/@title)]">
<!-- Title should be the one of the titles in the CSS -->
<tr class="{@title}"><td><xsl:value-of select="@title"/></td></tr>
</xsl:template>
</xsl:stylesheet>
問題不過是一些電影片名包含空格。我可以在名稱中使用空格嗎?如果沒有,是否有任何解決方法(除了在XML中有下劃線之外)?
更新:
好吧,我明白,這是不可能的。目前,我正在使用translate(@title, ' ', '-')
當CSS名稱由-
分隔時,這起作用。我仍然想知道是否有更好的方法來做到這一點。 :)
這是一個很好的觀點。 :)我用XSLT玩弄周圍,並想使它*動態*,但它實際上是硬編碼。我現在計劃創建一個小應用程序,根據XML中的標題創建CSS文件,以便算法將確定標題的顏色。是的,你可能會說我瘋了。 :) – whirlwin 2011-06-14 10:11:59