首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

用xsl排序輸出的問題?解决方案

2012-03-01 
用xsl排序輸出的問題?我有個XML文件,?xmlversion 1.0 encoding UTF-8 ?sectionname CallDetail

用xsl排序輸出的問題?
我有個XML文件,
<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<section   name= "CallDetailCDRTypeOrder ">
<param   name= "CSMOC "   seq= "1 "/>
<param   name= "CSMOT "   seq= "9 "/>
<param   name= "CSMTC "   seq= "2 "/>
<param   name= "CSCFW "   seq= "3 "   />
<param   name= "WAP01 "   seq= "4 "   />
<param   name= "DAOMT "   seq= "5 "   />
<param   name= "SMSMO "   seq= "6 "   />
<param   name= "GPRSS "   seq= "7 "   />
<param   name= "GPRSB "   seq= "8 "   />
</section>
1.我想用XSL對seq按升序徘序,我的xsl如下:
<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<xsl:stylesheet   version= "1.0 "   xmlns:xsl= "http://www.w3.org/1999/XSL/Transform "   xmlns:fo= "http://www.w3.org/1999/XSL/Format ">
<xsl:template   match= "/ ">
<xsl:for-each   select= "param ">
<xsl:sort     select= "seq "   data-type= "number() "   order= "ascending "> </xsl:sort>  
<xsl:value-of   select= "param "> </xsl:value-of>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet> ,用XML   SPY測試後沒輸出,大家幫我看?
2.如果我想把seq放在name前面如 <param   seq= "1 "   name= "CSMOC "/> 那在排序時xsl怎么寫,是這樣嗎?
<xsl:attribute   name= "seq "> <xsl:value-of   select= "seq "/> </xsl:attribute>  


[解决办法]
<?xml version= "1.0 " encoding= "UTF-8 "?>
<xsl:stylesheet version= "1.0 " xmlns:xsl= "http://www.w3.org/1999/XSL/Transform ">
<xsl:output indent= "yes " method= "xml "/>
<xsl:template match= "/ ">
<section name= "CallDetailCDRTypeOrder ">
<xsl:for-each select= "//param ">
<xsl:sort select= "@seq " data-type= "number " order= "ascending "/>
<xsl:element name= "param ">
<xsl:attribute name= "seq "> <xsl:value-of select= "@seq "/> </xsl:attribute>
<xsl:attribute name= "name "> <xsl:value-of select= "@name "/> </xsl:attribute>
</xsl:element>
</xsl:for-each>
</section>
</xsl:template>
</xsl:stylesheet>

热点排行