如何解决for-each-group 与 tokenize 结合从属性
我再次为创建适当的 XSLT (3.0) 以在我的文本中提到的人的不同列表而感到困惑。
XML 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<p>Lorem ipsum dolor sit <rs ref="#1">Romeo</rs>,consetetur sadipscing elitr,<rs ref="#2"
>Julia</rs> diam nonumy eirmod <rs ref="#2 #4">family</rs> invidunt ut labore et <other corresp="#3">Dolores</other></p>
我正在尝试获取@ref 或@corresp 的所有不同值的列表。注意@ref 或@corresp 中可以有两个值,因此需要对其进行标记。
结果可能是这样的:
<values>
<a>#1</a>
<a>#2</a>
<a>#3</a>
<a>#4</a>
</values>
在我的实际使用中,我将使用接收到的值在另一个文件中查找人员列表。
到目前为止,这是我所拥有的:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:template match="p">
<xsl:for-each-group select="descendant::*[self::rs or self::other]" group-by="@ref">
<a>
<xsl:copy-of select="@ref"/>
</a>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
我未能整合 tokenize(@ref,' ') 以及搜索的值在@ref 或@corresp 中。我错过了什么?
解决方法
像这样(编辑):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:template match="p">
<xsl:variable name="numbers" as="xs:string*">
<xsl:apply-templates select="rs/@ref|other/@corresp"/>
</xsl:variable>
<values>
<xsl:for-each select="distinct-values($numbers)">
<xsl:sort select="."/>
<a>
<xsl:value-of select="."/>
</a>
</xsl:for-each>
</values>
</xsl:template>
<xsl:template match="@*">
<xsl:sequence select="tokenize(.,'\s+')"/>
</xsl:template>
</xsl:stylesheet>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。