【发布时间】:2017-11-05 17:17:24
【问题描述】:
我有两个 xml 文件,一个包含货币,另一个包含国家/地区。
country.xml 示例:
<root>
<row>
<CountryName>Denmark</CountryName>
<CountryCode>DNK</CountryCode>
<Year>2016</Year>
<Value>5731118</Value>
</row>
<row>
Another country...
</row>
</root>
currency.xml 示例:
<valuta>
<overskrift>Valutaliste</overskrift>
<oppdatert>30.10.2017 09:00</oppdatert>
<timestamp>2017-10-30-09.18.29.485970</timestamp>
<valutakurs>
<land>USA</land>
<isokode>US</isokode>
<kode>USD</kode>
<enhet>1</enhet>
<navn>Dollar</navn>
</valutakurs>
<valutakurs>
Another currency...
</valutakurs>
</valuta>
我已经将我的 currency.xml 中的每一行 <kode></kode> 与 country.xml 合并,所以现在我在一个 xml 文件中得到了我需要的一切。
所以我想知道是否可以仅使用 xsl 将 DKK 与丹麦放在同一行?
或者我可以用 php 执行此操作并将它们合并到正确的位置开始吗?
这是我目前得到的。:
我想要用货币填充这张表,但它们需要在正确的位置。
编辑:
XSL 文件:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name = "year-search" match = "row" use = "Year"/>
<xsl:variable name="landkoder">NOR,SWE,DNK,FRO,FIN,ISL,GRL</xsl:variable>
<xsl:template match="/">
<html>
<body>
<h2>Nordic Countries</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Country</th>
<!--<th>Country Code</th>
<th>Year</th>-->
<th>Population</th>
<th>Currency</th>
</tr>
<xsl:for-each select = "key('year-search', '2016')">
<xsl:if test="contains($landkoder, CountryCode)">
<tr>
<td><xsl:value-of select="CountryName"/></td>
<!--<td><xsl:value-of select="CountryCode"/></td>
<td><xsl:value-of select="Year"/></td>-->
<td><xsl:value-of select="Value"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
【问题讨论】: