これを試してみると、データはソートされますが、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 を初めて使用し、苦労しています。