使用分组将文本组合在一起然后进行测试
因此,在这个糟糕的挤压排版产品中,我有时会看到链接和电子邮件地址被分开。示例:
<p>Here is some random text with an email address
<Link>example</Link><Link>@example.com</Link> and here
is more random text with a url
<Link>http://www.</Link><Link>example.com</Link> near the end of the sentence.</p>
所需的输出:
<p>Here is some random text with an email address
<email>[email protected]</email> and here is more random text
with a url <ext-link ext-link-type="uri" xlink:href="http://www.example.com/">
http://www.example.com/</ext-link> near the end of the sentence.</p>
元素之间似乎不会出现空格,这是一件好事。
我知道我需要在 p 模板中使用 xsl:for-each-group,但我不太明白如何通过 contains() 函数将组中的组合文本放入其中,以便区分电子邮件和 URL。帮助?
So in this grotty extruded typesetting product, I sometimes see links and email addresses that have been split apart. Example:
<p>Here is some random text with an email address
<Link>example</Link><Link>@example.com</Link> and here
is more random text with a url
<Link>http://www.</Link><Link>example.com</Link> near the end of the sentence.</p>
Desired output:
<p>Here is some random text with an email address
<email>[email protected]</email> and here is more random text
with a url <ext-link ext-link-type="uri" xlink:href="http://www.example.com/">
http://www.example.com/</ext-link> near the end of the sentence.</p>
Whitespace between the elements does not appear to occur, which is one blessing.
I can tell I need to use an xsl:for-each-group within the p template, but I can't quite see how to put the combined text from the group through the contains() function so as to distinguish emails from URLs. Help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用组相邻,那么您可以简单地字符串连接 current-group() ,如下所示
If you use group-adjacent then you can simply string-join the current-group() as in
这是基于身份模板的 XSLT 1.0 解决方案,对
元素进行了特殊处理。
我知道使用的 XPath 表达式是一些相当棘手的怪物,但是在 XPath 1.0 中选择相邻的兄弟姐妹并不容易(如果有人有更好的想法如何在 XPath 1.0 中做到这一点,请继续告诉我)。
表示“紧邻的前一个节点不能是
”,例如:仅是“连续第一个”的
元素。
表示
中,选择那些
(例如,它们不是“连续第一”),并且
current()
节点的 ID(始终是“连续第一个”的)必须等于:
本身就是“连续第一个”
如果这使得感觉。
应用到您的输入,我得到:
Here is an XSLT 1.0 solution based on the identity template, with special treatment for
<Link>
elements.I know that XPath expressions used are some quite a hairy monsters, but selecting adjacent siblings is not easy in XPath 1.0 (if someone has a better idea how to do it in XPath 1.0, go ahead and tell me).
means "the immediately preceding node must not be a
<Link>
", e.g.: only<Link>
elements that are "first in a row".means
<Link>
s, choose the ones that<Link>
(e.g. they are not "first in a row"), andcurrent()
node (always a<Link>
that's "first in a row") must be equal to:<Link>
that itself is "first in a row"If that makes sense.
Applied to your input, I get: