【发布时间】:2010-10-06 23:33:39
【问题描述】:
我试图弄清楚如何在我正在排序的节点之间保留空白节点。这是一个例子。
输入:
<a>
<b>
<c>
<d>world</d>
</c>
<c>
<d>hello</d>
</c>
</b>
<e>some other stuff</e>
</a>
期望的输出:
<a>
<b>
<c>
<d>hello</d>
</c>
<c>
<d>world</d>
</c>
</b>
<e>some other stuff</e>
</a>
这是我的 xslt:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="a/b">
<xsl:copy>
<xsl:apply-templates select="c">
<xsl:sort select="d"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
当我通过 xsltproc 运行它时,我得到了这个:
<a>
<b><c>
<d>hello</d>
</c><c>
<d>world</d>
</c></b>
<e>some other stuff</e>
</a>
我宁愿以后不要把它整理好。想法?
【问题讨论】: