如何限制 XSLT 中的字数? [英] How to limit the number of words in XSLT?
本文介绍了如何限制 XSLT 中的字数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定以下 XML 文档:
Given the following XML document:
<books>
<book>
<name>The problem of the ages</name>
</book>
<book>
<name>Filtering the tap</name>
</book>
<book>
<name>Legend of Atlantis</name>
</book>
</books>
我想从每本书的名字中最多提取 2 个词.可以假设单词是由空格分隔的字符序列.输出示例:
I want to take at most 2 words from the name of each book. Words can be assumed as being sequences of whitespace-separated characters. Example of output:
<library>
<record>The problem</record>
<record>Filtering the</record>
<record>Legend of</record>
</library>
我将如何使用单个 XSLT 实现这一目标?
How would I achieve this using a single XSLT?
推荐答案
尝试(在 3.0 中启用扩展文本):
Try (in 3.0 with expand-text enabled):
<xsl:template match="book/name">
<record>{tokenize(.) => subsequence(1, 2)}</record>
</xsl:template>
这篇关于如何限制 XSLT 中的字数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文