我有這樣的xml代碼:
<Car no="1" CarID="id_111-111">
<ProductionD>2001-07-12</ProductionD>
<MarketValue currency="$">1999.5</MarketValue>
<VisitedCountries>
<Country no="1">
Poland
</Country>
<Country no="2">
England
</Country>
</VisitedCountries>
<InspectionDates>
2011-09-13 2013-08-13
</InspectionDates>
</Car>
我想Car在表格中顯示所有內容。我想出了這個 xsl 代碼:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:output method="xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
<xsl:template match="/">
<html>
<head></head>
<body>
<table>
<xsl:for-each select="CarOwnerships/Cars/Car">
<tr>
<td><xsl:value-of select="ProductionD"/></td>
<td><xsl:value-of select="MarketValue"/></td>
<td><xsl:for-each select="VisitedCountries/Country">
<xsl:value-of select="Country"/>
</xsl:for-each></td>
<td><xsl:value-of select="InsuranceID"/></td>
<td><xsl:value-of select="Phone"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
但它只顯示第一個Country,而不是兩個。這怎么可能?
uj5u.com熱心網友回復:
<xsl:for-each select="VisitedCountries/Country">
<xsl:value-of select="Country"/>
</xsl:for-each>
應該
<xsl:for-each select="VisitedCountries/Country">
<xsl:value-of select="."/>
</xsl:for-each>
但是用 XSLT 2 做就<xsl:value-of select="VisitedCountries/Country"/>足夠了,不需要for-each.
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/365390.html
上一篇:來自SQLServer的XML
下一篇:如何從名稱相同的XML中獲取值
