【发布时间】:2017-08-09 18:24:20
【问题描述】:
我在这方面花了很多时间,并认为我会寻求可能的解决方案。这是我为测试而简化的 XML。
<Data>
<Superbill>
<Attributes>
</Attributes>
<Children>
<ListByMatter>
<ListByMatter>
<Children>
<ListofProfDetailTime>
<ListofProfDetailTime>
<Attributes>
<id>1</id>
<Date>2011-02-11</Date>
</Attributes>
</ListofProfDetailTime>
<ListofProfDetailTime>
<Attributes>
<id>2</id>
<Date>2010-11-02</Date>
</Attributes>
</ListofProfDetailTime>
<ListofProfDetailTime>
<Attributes>
<id>11</id>
<Date>2015-09-12</Date>
</Attributes>
</ListofProfDetailTime>
<ListofProfDetailTime>
<Attributes>
<id>1</id>
<Date>2013-11-12</Date>
</Attributes>
</ListofProfDetailTime>
</ListofProfDetailTime>
</Children>
</ListByMatter>
</ListByMatter>
</Children>
</Superbill>
</Data>
我在下面为我的转换编写了这个,但无法弄清楚如何从我在原始层次结构中得到的有序结果中替换旧节点。我正在使用这个网站http://xsltransform.net/ 来快速进行更改,但我确定我遗漏了一些简单的东西,或者它会比预期的要复杂得多。我最近才开始自学,需要一些指导。
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="//ListofProfDetailTime/ListofProfDetailTime">
<xsl:sort select="Attributes/Date" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:transform>
【问题讨论】:
-
您想要的输出 XML 看起来如何?