xslt中的Xpath比较

时间:2014-03-28 22:28:01

标签: xml xslt xpath

所以我试图弄清楚如何进行价值比较,我已经死了,

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" ><xsl:output ndent="no"     method="text"/>
<xsl:strip-space elements="*" />
<xsl:template match="/">
Famous Mountains of the World
<xsl:apply-templates />
</xsl:template>
<xsl:template match="mountain">
<xsl:apply-templates select="name[@language='English']" />
<xsl:apply-templates select="height" />
</xsl:template>
<xsl:template match="name[@language='English']">
 name: <xsl:value-of select="." /></xsl:template>
<xsl:template match="height">
Height:<xsl:value-of select="." /></xsl:template>
</xsl:stylesheet> 

我的结果看起来像

Famous Mountains of the World

Name: Mount Everest
Height:29035
Name: Mount Ranier
Height:14411
Name: Mount St. Helens
Height:8364
Name: Mount Washington
Height:6288
Name: Mount Bonnell
Height:800
Name: Mount Vesuvius
Height:4203
Name: Mount Etna
Height:10922

它很接近,但我应该以此结束。因为我一直在屠杀比较运算符。

Name: Mount Everest
Height: 29035
Name: Mount Ranier
Height: 14411
Name: Mount St. Helens
Height: 8364
Name: Mount Washington
Height: 6288
Name: Mount Bonnell
Height less than 801 feet

Name: Mount Vesuvius
Height: 4203
Name: Mount Etna
Height: 10922

非常感谢任何帮助。特别是小于801的输出。

这是XML。

<?xml version="1.0" encoding="UTF-8"?>
<!-- Note: This is a comment-->
<?xml-stylesheet type="text/xsl" href="Asg09.xsl"?>
<FamousMountains>
 <mountain>
    <name language="English">Mount Everest</name>
    <name language="PigLatin">ountMa verestEa</name>
    <location>Nepal</location>
    <height units="feet">29035</height>
  </mountain>
  <mountain>
   <name language="English">Mount Ranier</name>
    <location>Washington</location>
    <height units="feet">14411</height>
  </mountain>
  <mountain>
    <name language="English">Mount St. Helens</name>
    <location>Washington</location>
    <height units="feet">8364</height>
  </mountain>
  <mountain>
    <name language="English">Mount Washington</name>
    <name language="PigLatin">ountMa ashingtonWa</name>
    <location>New Hampshire</location>
    <height units="feet">6288</height>
  </mountain>
  <mountain>
    <name language="English">Mount Bonnell</name>
    <name language="PigLatin">ountMa onnellBa</name>
    <location>Austin</location>
    <height units="feet">800</height>
  </mountain>
  <mountain>
    <name language="English">Mount Vesuvius</name>
    <name language="PigLatin">ountMa esuviusVa</name>
    <location>Italy</location>
    <height units="feet">4203</height>
  </mountain>
  <mountain>
    <name language="English">Mount Etna</name>
    <name language="PigLatin">ountMa tnaEa</name>
    <location>Sicily</location>
    <height units="feet">10922</height>
  </mountain>
</FamousMountains>

试图弄清楚如何区分某些数字,在这种情况下数字小于801,所以就像山是800.山峰的高度小于801英尺。

1 个答案:

答案 0 :(得分:1)

只需添加一个模板规则:

<xsl:template match="height[. &lt; 800]">
Height: less than 800 feet
</xsl:template>