写xsl,输出最大值!!!!!~~~~(>_<)~~~~
xml:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE numbers SYSTEM "maximum.dtd">
<numbers>
<num>18</num>
<num>-1</num>
<num>3</num>
<num>5</num>
<num/>
<num>23</num>
<foo>hello</foo>
<num>-3</num>
<num>2</num>
<num>7</num>
<num>4</num>
<num></num>
</numbers>
输出自然就是,23啦。。
但是<num></num>,<num/>
改怎么处理呢??
哪位好心的高手帮帮忙写一下xsl参考参考!!!!!!!!!!!!!!!1
[解决办法]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
exclude-result-prefixes="xs fn">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="var1_instance_max" as="node()" select="."/>
<xsl:variable name="var2_map_select_numbers" as="xs:decimal*">
<!-- 给变量赋值 -->
<xsl:for-each select="$var1_instance_max/*:numbers[fn:namespace-uri() eq '']/*:num[fn:namespace-uri() eq '']">
<xsl:variable name="var3_cur_seq_" as="node()" select="."/>
<xsl:sequence select="xs:decimal(xs:string($var3_cur_seq_))"/>
</xsl:for-each>
</xsl:variable>
result:
<xsl:if test="fn:exists(fn:max($var2_map_select_numbers))">
<xsl:sequence select="xs:string(fn:max($var2_map_select_numbers))"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>