我有以下XML:
<items>
<item>
<locations>
<location>
<latitude>-100</latitude>
<longitude>10</longitude>
</location>
<location>
<latitude>10</latitude>
<longitude>10</longitude>
</location>
</locations>
</item>
<item>
<locations>
<location>
<latitude>10</latitude>
<longitude>10</longitude>
</location>
<location>
<latitude>10</latitude>
<longitude>10</longitude>
</location>
</locations>
</item>
<items>
我需要计算纬度或经度值无效的项目。
有效纬度介于-90和90之间。有效经度介于-180和180之间。
为方便发布,让我们试着让它计算纬度大于-90。
我尝试了以下方法,但没有一项工作:
count(//item[locations/location[number(latitude) > -90])
count(//item[locations/location[number(latitude)] > -90)
count(//item[locations/location/*[number(latitude) > -90])
count(//item[locations/location/*[number(latitude)] > -90)
count(//item[locations/location/*[number(name() = latitude)] > -90)
count(//item[locations/location/*number([name() = latitude]) > -90)
count(//item[number(deal/locations/location/*[name()=latitude]) > -90])
有人知道这是否可行?如果不是,有人可以想到一个整洁的解决方法吗?
提前谢谢大家。
答案 0 :(得分:1)
我认为您需要使用小于,不大于 - 您希望纬度小于 -90。
e.g。运行这个xslt
<xsl:template match="/">
<GoodItems>
<xsl:value-of select="count(//item[not(locations/location[number(latitude) < -90
or number(latitude) > 90
or number(longitude) < -180
or number(longitude) > 180])])" />
</GoodItems>
<LatTooSmall>
<xsl:value-of select="count(//item[locations/location[number(latitude) < -90]])" />
</LatTooSmall>
<LatTooBig>
<xsl:value-of select="count(//item[locations/location[number(latitude) > 90]])" />
</LatTooBig>
<LongTooSmall>
<xsl:value-of select="count(//item[locations/location[number(longitude) < -180]])" />
</LongTooSmall>
<LongTooBig>
<xsl:value-of select="count(//item[locations/location[number(longitude) > 180]])" />
</LongTooBig>
</xsl:template>
针对此测试用例xml文档:
<items>
<item>
<locations>
<location>
<latitude>10</latitude>
<longitude>10</longitude>
</location>
</locations>
</item>
<item>
<locations>
<location>
<latitude>-100</latitude>
<longitude>10</longitude>
</location>
</locations>
</item>
<item>
<locations>
<location>
<latitude>123</latitude>
<longitude>10</longitude>
</location>
</locations>
</item>
<item>
<locations>
<location>
<latitude>0</latitude>
<longitude>-200</longitude>
</location>
</locations>
</item>
<item>
<locations>
<location>
<latitude>0</latitude>
<longitude>500</longitude>
</location>
</locations>
</item>
</items>
返回以下内容:
<GoodItems>1</GoodItems>
<LatTooSmall>1</LatTooSmall>
<LatTooBig>1</LatTooBig>
<LongTooSmall>1</LongTooSmall>
<LongTooBig>1</LongTooBig>
如果您有xslt 2,也可以使用abs()
,尽管Dimitre在1.0 here