- 首页
- 其他开发
- 'Null' 的 XSLT/XPath 测试
'Null' 的 XSLT/XPath 测试
[英] XSLT/XPath test for 'Null'
本文介绍了'Null' 的 XSLT/XPath 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下检查 xml 中的字符串......但是,我需要创建另一个测试来检查变量 $validItems
中的 'Null' 或没有文本在第一个线...
<div class="text"><xsl:when test="$horizontal"><div class="holder"><div class="frame"><div class="slides-descriptions"><xsl:apply-templates select="$validItems" mode="horizontal"/>
<div class="switcher"/>
</xsl:when><xsl:否则><div class="slides-descriptions"><xsl:apply-templates select="$validItems" mode="vertical"/>
<div class="switcher"/></xsl:否则></xsl:选择>
</xsl:if>
我将如何测试变量 xsl:if test=$validItems?
解决方案
如果我明白你的要求,
<xsl:if test="$validItems[(Caption | CalltoAction)[not(string(.))]]">
会做的.换句话说,如果 $validItems 节点集中的元素具有字符串值为空的 Caption 或 CalltoAction 子元素".你也可以说
I have the following which checks for a string within the xml... however, I need to create another test to check for 'Null' or no text within the variable $validItems
at the 1st line...
<xsl:if test="$validItems[(Caption | CalltoAction)[string(.)]]">
<div class="text">
<xsl:choose>
<xsl:when test="$horizontal">
<div class="holder">
<div class="frame">
<div class="slides-descriptions">
<xsl:apply-templates select="$validItems" mode="horizontal"/>
</div>
<div class="switcher"/>
</div>
</div>
</xsl:when>
<xsl:otherwise>
<div class="slides-descriptions">
<xsl:apply-templates select="$validItems" mode="vertical"/>
</div>
<div class="switcher"/>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:if>
How would I go about testing the variable xsl:if test=$validItems?
解决方案
If I understand what you're asking for,
<xsl:if test="$validItems[(Caption | CalltoAction)[not(string(.))]]">
will do it. In other words, "if there is an element in the $validItems node-set that has a Caption or CalltoAction child element whose string value is empty". You could also say
<xsl:if test="$validItems[(Caption | CalltoAction)[. = '']]">
这篇关于'Null' 的 XSLT/XPath 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!