给定下面的XML和相应的XSL代码,当条件不满足时,我们为什么要得到输出?
据我所知,由于存在多个will节点,因此它将考虑第一个节点,然后它将看到该条件为false,因此不应该显示输出。
XML :
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="02-01.xsl"?>
<ancient_wonders>
<wonder>
<name language="English">Colossus of Rhodes1</name>
<name language="Greek">Κολοσσός της Ρόδου1</name>
<location>Rhodes, Greece</location>
<height units="feet">107</height>
<main_image filename="colossus.jpg" w="528" h="349"/>
<source sectionid="101" newspaperid="21"></source>
</wonder>
<wonder>
<name language="English">Colossus of Rhodes2</name>
<name language="Greek">Κολοσσός της Ρόδου2</name>
<location>Rhodes, Greece</location>
<height units="feet">120</height>
<main_image filename="colossus.jpg" w="528" h="349"/>
<source sectionid="103" newspaperid="21"></source>
</wonder>
</ancient_wonders>XSLT :
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- Output Method -->
<xsl:output method="html"/>
<!-- Root Template -->
<xsl:template match="/">
<html>
<body>
<p><b>Output 1 :</b></p>
<xsl:if test="ancient_wonders/wonder/height != 107">
<p>Height = <xsl:value-of select="." /></p>
</xsl:if>
<p><b>Output 2 :</b></p>
<xsl:if test="ancient_wonders/wonder/height != 107">
<p>Height = <xsl:value-of select="ancient_wonders/wonder/height" /></p>
</xsl:if>
</body>
</html>
</xsl:template>
</xsl:stylesheet>输出:
Output 1 :
Height = Colossus of Rhodes1 Κολοσσός της Ρόδου1 Rhodes, Greece 107 Colossus of Rhodes2 Κολοσσός της Ρόδου2 Rhodes, Greece 120
Output 2 :
Height = 107发布于 2019-03-08 14:05:54
这句话:
ancient_wonders/wonder/height在文档中选择两个height元素。测试:
test="ancient_wonders/wonder/height != 107"返回true,因为比较节点集中至少有一个满足条件(请参阅:https://www.w3.org/TR/1999/REC-xpath-19991116/#booleans )的节点。
只有xsl:value-of指令具有只返回所选节点集的第一个节点的值的异常;这种异常在XSLT2.0中被删除。
https://stackoverflow.com/questions/55064686
复制相似问题