使用 XSLT 1.0 从 XHTML 获取 N 个字符的介绍文本 [英] Get N characters introduction text with XSLT 1.0 from XHTML
本文介绍了使用 XSLT 1.0 从 XHTML 获取 N 个字符的介绍文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 XSLT 1.0 从 XHTML 获取前 n 个字符?我正在尝试为新闻创建介绍文本.
How I can get first n characters with XSLT 1.0 from XHTML? I'm trying to create introduction text for news.
- 一切都是 UTF-8
- HTML 实体感知 (
&
),一个实体 = 一个字符 - HTML 标记感知(添加缺少的结束标记)
- 输入 HTML 始终有效
- 如果输入文本超过 n 个字符,则添加..."以结束输出
- 输入标签仅限于:a、img、p、div、span、b、strong
- Everything is UTF-8
- HTML entity aware (
&
), one entity = one character - HTML tag aware (adds missing end tags)
- Input HTML is always valid
- If input text is over n chars add '...' to end output
- Input tags are restricted to: a, img, p, div, span, b, strong
示例输入 HTML:
<img src="image.jpg" alt="">text <a href="http://domain.tld">link here</a>
9 个字符的输出示例:
Example output with 9 characters:
<img src="image.jpg" alt="">text <a href="http://domain.tld">link...</a>
示例输入 HTML:
<p><a href="http://domain.tld">link here</a> text</p>
4 个字符的输出示例:
Example output with 4 characters:
<p><a href="http://domain.tld">link...</a></p>
推荐答案
正如许多人所指出的:这会很快变得非常混乱.所以我只是在 DB 中添加了另一个字段,其中包含介绍文本.
As indicated by many: this gets very messy very fast. So I just added another field to DB which has the introduction text.
这篇关于使用 XSLT 1.0 从 XHTML 获取 N 个字符的介绍文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文