当我尝试这个时,我的数据排序,但 XML 标记被剥离。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="searchResults/searchResult">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort select="//TSN" order="descending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
当我这样做时,XML 输出格式是正确的,但它没有排序。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort select="//TSN" order="descending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这是我的 XML 示例:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<info><statusCode>0</statusCode><messages/></info>
<search>
<options><maxMatches>100</maxMatches><units>m</units></options>
<resultsCount>3</resultsCount>
<totalPages>1</totalPages>
<searchResults>
<searchResult>
<resultNumber>1</resultNumber>
<fields>
<LocationState>OK</LocationState><TSN>N</TSN><LocationCity>TULSA</LocationCity>
</fields>
</searchResult>
<searchResult>
<resultNumber>2</resultNumber>
<fields>
<LocationState>OK</LocationState><TSN>Y</TSN><LocationCity>BIXBY</LocationCity>
</fields>
</searchResult>
<searchResult>
<resultNumber>3</resultNumber>
<fields>
<LocationState>OK</LocationState><TSN>N</TSN><LocationCity>COWETA</LocationCity>
</fields>
</searchResult>
</searchResults>
<origin><adminArea3 type="State">OK</adminArea3></origin>
</search>
</response>
有任何想法吗?我是 XSLT 的新手并且正在苦苦挣扎。