可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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: