xslt - 编程技术 [英] xslt - programming techniques

查看:20
本文介绍了xslt - 编程技术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此 链接.

我们知道使用这段代码,我们可以消除冗长的xsl选择方法

We know that using this code, we can eliminate verbose xsl choose method

concat(
substring(Str1,1 div Cond),
substring(Str2,1 div not(Cond))
)

但是我们可以在条件"中指定什么,只是为了检查节点的存在或不存在?

However what can we specify in 'condition', just to check for presence or absence of nodes?

我们不能指定

concat(
substring(Str1,1 div test="/node"),
substring(Str2,1 div not(test="/node"))
)

会抛出语法错误.

推荐答案

试试这个表达式(其中 node 是您要测试的节点的名称):

Try this expression (where node is the name of the node you want to test):

<xsl:value-of select="concat(
   substring('Yes', 1 div not(not(/root/node))), 
   substring('No', 1 div not(/root/node)))"/>

或者更好

<xsl:value-of select="concat(
   substring('Yes', 1 div boolean(/root/node)), 
   substring('No', 1 div not(/root/node)))"/>

应用于此 XML 时,则输出 Yes

When applied to this XML, then Yes is output

<root>
   <node>Test</node>
</root>

但是当应用于这个 XML 时,输出 No

But when applied to this XML, the No is output

<root>
   <othernode>Test</othernode>
</root>

这篇关于xslt - 编程技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆