這是我的第一篇文章。對不起,如果它有點馬虎。所以我正在編譯WFB.xml中的列表。它有很多關於世界所有國家的信息。我試圖獲取每個國家的名稱並將其打印在我的h2標籤中。但是,它將列表中的第一個名稱打印出來,直到所有地方都被排序。XSL重複相同的值,但計算不同值的正確數量
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:variable name="config"
select="document('fb_config.xml')"/>
<xsl:variable name="wfb"
select="document('world_factbook_2008.xml')"/>
<xsl:template match="/">
<xsl:text disable-output-escaping='yes'>
<!DOCTYPE html>

</xsl:text>
<html>
<head>
<title>
<xsl:text>CIA World Factbook</xsl:text>
</title>
</head>
<body>
<xsl:variable name="wfbYear"
select="$wfb/WFB/@YEAR"/>
<h1>
<xsl:value-of select="concat('CIA World ', $wfbYear, ' Factbook')" />
<xsl:text></xsl:text>
</h1>
<xsl:if test="$config/config/order/@output = 'asc'">
<!-- DIV TEST --> <xsl:apply-templates select="$wfb/WFB/PLACE" >
<xsl:sort order="ascending"/>
</xsl:apply-templates>
</xsl:if>
<xsl:if test="$config/config/order/@output = 'dec'">
<!-- DIV TEST --> <xsl:apply-templates select="$wfb/WFB/PLACE" >
<xsl:sort order="descending"/>
</xsl:apply-templates>
</xsl:if>
</body>
</html>
</xsl:template>
<xsl:template match="PLACE">
<div style="border:1px solid black;">
<h2>
<xsl:apply-templates select="$wfb/WFB/PLACE/NAME"/>
</h2>
</div>
</xsl:template>
<xsl:template match="NAME">
<xsl:value-of select="current()"/>
</xsl:template>
</xsl:stylesheet>
目前此代碼一遍又一遍地打印Adelie Land。這是xml文件中的第一個名稱。
我覺得我的錯誤是:
<xsl:template match="PLACE">
<div style="border:1px solid black;">
<h2>
<xsl:apply-templates select="$wfb/WFB/PLACE/NAME"/>
</h2>
</div>
</xsl:template>
如果我拿出我的模板匹配的名字,那麼這個打印出所有的名字在一個單一的線,並做到這一點,直到所有的地方都被分揀。
任何提示或建議?
這是XML頁面的外觀閱讀:前
關於發佈樣本輸入個XML如何?不一定是整個列表。 – 2014-11-23 03:46:40