Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么是测试=";元素[@attribute]”;你在XSLT中做什么?_Xslt_Xpath - Fatal编程技术网

什么是测试=";元素[@attribute]”;你在XSLT中做什么?

什么是测试=";元素[@attribute]”;你在XSLT中做什么?,xslt,xpath,Xslt,Xpath,这到底是做什么的 <xsl:if test="./employee/first-name[@id='14']" > 我的意思是,如果/employee/first name[@id]!=空或“,或什么 编辑 我已经编辑了上面的语句,所以它测试id=14的元素名是否有一个主体,或者它的主体是否包含数据,或者如果名事件没有主体,则返回true?如果中的查询返回至少一个节点,则条件求值为true 您提供的新XSLT表达式: <xsl:if test="./employee/fi

这到底是做什么的

<xsl:if test="./employee/first-name[@id='14']" >

我的意思是,如果
/employee/first name[@id]
!=<代码>空或
,或什么

编辑 我已经编辑了上面的语句,所以它测试id=14的元素名是否有一个主体,或者它的主体是否包含数据,或者如果名事件没有主体,则返回true?

如果
中的查询返回至少一个节点,则条件求值为true

您提供的新XSLT表达式:

<xsl:if test="./employee/first-name[@id='14']" >

似乎缺少一些片段,因为last
或“
将抛出错误。但是,让我们看看:

./ search within current node employee/first-name for an employee tag with an first-name child tag [@id] where first-name tag have an id attribute !=null and that first-name tag have some value /在当前节点内搜索 带有名字子标记的雇员标记的雇员/名字 [@id]其中first name标记具有id属性 !=null,并且该名字标记有一些值
测试表达式(如传统语言中的
if
)。表达式的结果将作为布尔值计算

在您的例子中,表达式是一个XPath选择器(
/employee/first name[@id]
)-它将始终返回一个节点集。只有当节点集为空时(例如,未找到匹配节点),节点集才会评估为
false

表达式也可以类似于
number(/employee/id)
。现在,表达式结果是一个数字,如果它为零或在所有其他情况下为NaN,则计算结果为
false
true

false
的其他值是空字符串
'
true
在所有其他情况下)和
false()
本身的结果。请注意,还有一个
true()
函数返回布尔值
true


另请注意,根据所述字符串规则,字符串
'false'
的计算结果为
true

这里有一个很好的在线XPath表达式计算工具:输入一些XML并尝试表达式。请重新回答上面修改过的问题好吗? ./ search within current node employee/first-name for an employee tag with an first-name child tag [@id] where first-name tag have an id attribute !=null and that first-name tag have some value