开发者

Can XML/XSLT substring-before take more than one match-string as a second argument?

XML/XSLT Newb question. I apologise for this. I got handed a chunk of code and asked to 'have a look at this', and I'm not particularly familiar with XSLT :(

I've got an .xsl file that tr开发者_如何学JAVAansforms a chunk of story text, and plucks out the first sentence by using the line:

<xsl:value-of select="substring-before(story,'.')" />

It works fine, mostly. The problem is this: if the first sentence ends in a question mark or an exclamation mark, I end up with two sentences.

Is there any way of doing something along the lines of:

<xsl:value-of select="substring-before(story,'.' or '!' or '?')" />

Or is there a way of using regex, e.g.

/^(.*?)[.?!]\s/

...to extract just the very first sentence?

Or am I hugely off the mark and best waiting for the resident XSLT expert to get back? :)


If your character set for punctuation is relative limited you could map it all to a single character (e.g. period) using the translate function and then use the substring-before. e.g.

<xsl:value-of select="substring-before(translate(story,'?!','..'),'.')" />

Edit: I should say in answer to your actual question, no - you can't have a boolean expression as the second argument in substring-before.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜