xslt: substring-before

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

I have the folowing xml code:

14 3127 3 78

Now i'd like to only grab the first number of each node to set a background image. So for each node i have the folowing xslt:

   background-image:url('../icon_.png'); 

Problem is that substring before doesn't return anything when there's no space. Any easy way around this?

回答1:

You can use xsl:when and contains:

       background-image:url('../icon_.png');     background-image:url('../icon_.png');


回答2:

You can make sure that there is always a space, maybe not the prettiest but at least it's compact :)



回答3:

You can use functx:substring-before-if-contains

The functx:substring-before-if-contains function performs substring-before, returning the entire string if it does not contain the delimiter. It differs from the built-in fn:substring-before function, which returns a zero-length string if the delimiter is not found.

Looking at the source code, it's implemented as follows:



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!