内容简介:翻译自:https://stackoverflow.com/questions/18665516/xslt-set-default-value-when-selected-one-is-not-available
是否可以使用<xsl:value-of>?设置默认值?我试图使用XSLT样式表生成 JSON
输出,并且在处理阶段可能无法使用某些字段.这会留下一个空值,这会破坏JSON文档的有效性.理想情况下,如果没有默认值,我可以设置默认值.所以在以下情况下:
"foo_count": <xsl:value-of select="count(foo)" />
如果<foo>在文档中不可用,我可以将其设置为0吗?
它是 choose
<xsl:choose>
<xsl:when test="foo">
<xsl:value-of select="count(foo)" />
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
或使用 if test
<xsl:if test="foo"> <xsl:value-of select="count(foo)" /> </xsl:if> <xsl:if test="not(foo)"> <xsl:text>0</xsl:text> </xsl:if>
或使用 named template for calling
<xsl:template name="default">
<xsl:param name="node"/>
<xsl:if test="$node">
<xsl:value-of select="count($node)" />
</xsl:if>
<xsl:if test="not($node)">
<xsl:text>0</xsl:text>
</xsl:if>
</xsl:template>
<!-- use this in your actual translate -->
<xsl:call-template name="default">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
翻译自:https://stackoverflow.com/questions/18665516/xslt-set-default-value-when-selected-one-is-not-available
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- java8下的我们应该这样用时间 原 荐
- WPF 的命令的自动刷新时机——当你 CanExecute 会返回 true 但命令依旧不可用时可能是这些原因
- springboot 默认日志配置
- HDFS副本设置——默认3
- WPF 绑定的默认模式
- StackOverflow转向默认使用HTTPS
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Web Security Testing Cookbook
Paco Hope、Ben Walther / O'Reilly Media / 2008-10-24 / USD 39.99
Among the tests you perform on web applications, security testing is perhaps the most important, yet it's often the most neglected. The recipes in the Web Security Testing Cookbook demonstrate how dev......一起来看看 《Web Security Testing Cookbook》 这本书的介绍吧!