xslt中是否有诸如trim之类的操作? [英] is there any operation such as trim in xslt?

查看:43
本文介绍了xslt中是否有诸如trim之类的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个 xslt 代码,它将一个 xml 文件转换为一个包含大量表格的 html 文件,其中一列包含消息(非常长的消息),但该行以验证通过"或验证失败"

i wrote a xslt code which converts a xml file to a html file which contains lot of tables, one of the column contains messages(very long messages), but that line starts with either of the two words "Verification Passed" or "Verification failed"

我的要求是,如果验证失败,则将整个表格行设为红色,如果验证通过,则将整个表格行设为绿色

My requirement is to make the entire table row red if verification failed and make entire table row green if verification passed

 <xsl:choose>
  <xsl:when test="contains(@message,'Verification failed:')"><td bgcolor="#FF0000">   <xsl:value-of select="@Message"/></td></xsl:when>
  <xsl:when test="contains(@message,'Verification passed:')"><td bgcolor="#00FF00"><xsl:value-of select="@Message"/></td></xsl:when>   
  <xsl:otherwise><td> <xsl:value-of select="@Message"/></td></xsl:otherwise>
</xsl:choose> 

推荐答案

不幸的是,您没有说出您希望trim()"函数执行的操作.但是从您对要求的描述来看,我猜 normalize-space() 已经足够接近了:

Unfortunately you don't say what you expect your "trim()" function to do. But from your description of the requirement, I would guess that normalize-space() is close enough:

starts-with(normalize-space(message), 'Verification passed'))

XPath normalize-space() 函数与 Java trim() 方法的不同之处在于 (a) 它用单个空格替换内部空白字符序列,以及 (b) 它对空白的定义略有不同.

The XPath normalize-space() function differs from the Java trim() method in that (a) it replaces internal sequences of whitespace characters by a single space, and (b) it has a slightly different definition of whitespace.

这篇关于xslt中是否有诸如trim之类的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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