我想通过查询xml文档来创建一个html表格。我正在使用xslt。xslt按子元素排序
这是问题所在。 “父”节点包含许多“子”节点。我必须按排序顺序(降序)包含父节点的@name和“子节点”节点的数量。所以我在做
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="parent[count(child) > 3]">
<html>
<table border="1">
<xsl:for-each select=".">
<xsl:sort select="{count(child)}" data-type="number" order="descending"/>
<tr>
<td><b><xsl:value-of select="@name" /></b></td>
<td><xsl:value-of select="count(child)" /></td>
</tr>
</xsl:for-each>
</table>
</html>
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>
我得到的HTML,但唯一的问题是我没有得到它按照子元素的排序顺序。我怀疑我使用的计数不正确:xsl:sort?你能帮我吗?
输入XML
<outer>
<parent name="abc" attr1="22664136" attr2="647500">
<child percentage="11">aaa</child>
<child percentage="35">bbb</child>
<child percentage="50">ccc</child>
</parent>
<parent name="ggg" attr1="3249136" attr2="28750"/>
<parent name="ghi" attr1="29183032" attr2="2381740">
<child2>
<name>ppp</name>
<attr1>1507241</attr1>
</child2>
</parent>
<parent name="qwe" attr1="10342899" attr2="1246700"/>
<parent name="lkj" attr1="65647" attr2="440">
<child percentage="100">jjj</child>
</parent>
</outer>
提供您输入XML太 –
@SivaCharan增加I/P XML。 – abc
我不确定是否有意为之,但除了文本元素外,您提供的输入文档没有任何匹配模板:您的所有“父”元素都没有“count(child)> 3”。 – btlachance