问题是使用XSL合并和排序多个XML文件,并输出有效的HTML,可在Firefox >= 3.5以及可能的情况下在IE >= 7上查看。答案应尽可能简单(性能不重要)。
文件a.xml
<?xml version="1.0"?>
<root>
<tag>cc</tag>
<tag>aa</tag>
</root>
文件 b.xml
<?xml version="1.0"?>
<root>
<tag>xx</tag>
<tag>bb</tag>
</root>
文件 index.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="merge.xslt"?>
<list>
<entry>a.xml</entry>
<entry>b.xml</entry>
</list>
文件合并.xslt
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ph="http://ananas.org/2003/tips/photo">
<xsl:output method="html"/>
<xsl:template match="list">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="entry">
<xsl:for-each select="document(.)/root/tag">
<!-- This will only sort the values of a single file -->
<xsl:sort select="." data-type="text" order="ascending" />
- <xsl:value-of select="."/> <br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
当前输出:
aa
cc
bb
xx
期望的输出:
aa
bb
cc
xx
xsl:for-each
... - Dimitre Novatchev