从外部文档中提取的 XSLT 排序列表项

XSLT sort list items pulled in from external documents

我需要对从外部 xml 文件集合中提取的列表值进行排序。

输入文档:

<book>
    <div type="chapter">
        <div xml:id="d9">
            <head>First Chapter</head>
            <p>First paragraph ...</p>
        </div>
        <DOI>12.3456/789012345.n1</DOI>
    </div>
</book>

外部文档 1:

<rdf:RDF
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:luxid="http://www.temis.com/luxid#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Description rdf:about="http://dx.doi.org/10.4135/9781446270288.n2">
        <dc:identifier>12.3456/789012345.n1</dc:identifier>
    </rdf:Description>
    <rdf:Description rdf:about="http://www.temis.com/luxid#/Entity/Bookshelf/HSSTerm/personal values">
        <luxid:lemmatizedForm>personal values</luxid:lemmatizedForm>
        <luxid:score>0.31063202</luxid:score>
    </rdf:Description>
    <rdf:Description rdf:about="http://www.temis.com/luxid#/Entity/Bookshelf/HSSTerm/athletes">
        <luxid:lemmatizedForm>athletes</luxid:lemmatizedForm>
        <luxid:score>0.32773998</luxid:score>
    </rdf:Description>
</rdf:RDF>

还有更多相同格式的外部文档。

此 XSLT 从基于 DOI 元素的外部文档中提取关键字。

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns="http://www.tei-c.org/ns/1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:doi="http://www.doi.org/2004/DOISchema"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:luxid="http://www.temis.com/luxid#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="2.0" exclude-result-prefixes="dc owl luxid rdfs rdf">

    <xsl:output method="xml" encoding="UTF-8" version="1.0"/>

    <xsl:variable name="rdfFiles" select="collection('file:///C:/files/?select=*.xml*')"/>

    <!-- Chapter level keywords -->

    <xsl:template match="div[@type='chapter']/DOI">
        <xsl:element name="div">
            <xsl:element name="list">
                <xsl:for-each select="$rdfFiles//rdf:RDF//rdf:Description/luxid:lemmatizedForm[ancestor::rdf:RDF//rdf:Description/dc:identifier/text() = current()/text()]">
                    <xsl:sort data-type="number" select="following-sibling::luxid:score"/>
                    <xsl:element name="item">
                        <xsl:value-of select="."/>
                    </xsl:element>
                </xsl:for-each>
            </xsl:element>
        </xsl:element>
        <xsl:element name="DOI">
            <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

我需要按数字顺序对列表中的关键字进行排序 - 这是通过外部文档中的 luxid:score 元素表示的。但是我有什么不工作。

预期输出:

关键词 "athletes" 应该出现在列表中的 "personal values" 之前。

The keyword "athletes" should come before "personal values" in the list. I need to sort the keywords in the list in numerical order - which is expressed via the luxid:score element

"personal values" 的值为 0.31063202,"athletes" 的值为 0.32773998。您按此字段的数字顺序排序,因此较低的值排在第一位:运动员之前的个人价值。

如果你想反转,那么你可以添加 order="descending"xsl:sort 元素,这将产生最高值在前的效果。