在XSLT中test ="element [@attribute]"做了什么?

Muh*_*edy 2 xslt xpath

这究竟是做什么的?

<xsl:if test="./employee/first-name[@id='14']" >
Run Code Online (Sandbox Code Playgroud)

我的意思是,当将这种情况是真实的,如果./employee/first-name[@id]!= null或者"",还是什么?

编辑

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

int*_*tgr 11

如果查询<xsl:if test=...>返回至少一个节点,则条件evaulates为true.

您提供的新XSLT表达式:

<xsl:if test="./employee/first-name[@id='14']" >
Run Code Online (Sandbox Code Playgroud)

将计算为,当且仅当存在一个first-name下节点employee,其id属性等于字符串'14'

<employee><first-name id="" /></employee>     <!-- does NOT match -->
<employee><first-name id="014" /></employee>  <!-- does NOT match -->
<employee>
  <first-name id="foobar" />
  <first-name id="14" />                      <!-- DOES match -->
</employee>
Run Code Online (Sandbox Code Playgroud)