[英]xslt 1.0: sorting elements across multiple documents
我在xml文檔(稱為result.xml)中有一個搜索結果,作為對容器文檔(mycore.xml)的引用列表,這些文檔引用了另一個文檔中的“真實”內容文件(mets.xml)。 問題不僅僅在於格式化第三級文檔,還在於根據mets.xml文檔中第三級文檔(發布數據的發布年份)上的元素對整個結果進行排序。 這是一個大概的圖片:
/result/doc/@href --> document('mycore_1.xml')/mycore/file/@href -> document('mets_1.xml')/mets/dmdSec
/doc/@href --> document('mycore_2.xml')/mycore/file/@href -> document('mets_2.xml')/mets/dmdSec
我有一個使用XSLT 2.0函數的解決方案,但在XSLT 1.0中使用調用或應用模板無法正常工作。 不幸的是,在選擇的CMS中,Typo3,我只能使用XSLT 1.0處理器。
為result.xml
<result>
<doc href="mycore_1.xml"/>
<doc href="mycore_2"/>
...
</result>
mycore_1.xml
<mycore>
<file href="mets_1.xml">
</mycore>
mets_1.xml
<mets>
<dmdSec>
<mods>
<dataIssued>1980
</dateIssued>
<namePart>Jones
</namePart>
...
</mods>
</dmdSec>
</mets>
這是適用於XSLT 2.0的函數定義。
<!-- returns a node-set of all dmdSec -->
<xsl:function name="mets:fetchFiles">
<xsl:param name="docs"/>
<xsl:for-each select="$docs">
<xsl:for-each select="document(@href)/mycore/file">
<xsl:for-each select="document(@href)/mets/dmdSec">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:function>
這里是調用和排序:
<xsl:for-each select="fetchFiles(result/doc)">
<xsl:sort select="mods/dateIssued"/>
<xsl:call-template name="theFormatting">
... <!-- format and output the dmdSec/mods -->
</xsl:call-template>
</xsl:for-each>
對我來說,困難似乎是,該函數中的copy-of返回修改后的輸入,但是使用調用模板,我只是使用copy-of輸出生成。 有沒有一種方法可以替換輸入,以便對dmdSec元素和子元素進行排序和格式化?
任何回應將不勝感激!
霍爾格
好吧,如果您想在XSLT 1.0中實現XSLT 2.0功能,則可以將其作為模板,然后返回結果樹片段,您可以將其轉換為節點集(使用exsl:node-set($rtf)
)進行排序。
但坦率地說,我不明白為什么要執行所有這些步驟, document
功能強大到足以處理多個節點並返回多個文檔,因此您應該能夠使用
<xsl:for-each select="document(document(result/doc/@href)/mycore/file/@href)/mets/dmdSec">
<xsl:sort select="mods/dateIssued"/>
...
</xsl:for-each>
我分別希望並建議使用apply-templates例如
<xsl:apply-templates select="document(document(result/doc/@href)/mycore/file/@href)/mets/dmdSec">
<xsl:sort select="mods/dateIssued"/>
</xsl:apply-templates>
並有
<xsl:template match="mets/dmdSec">
...
</xsl:template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.