我真的很感激這里的一些幫助。XSLT 相對較新,并試圖通過 XSLT 將 2 個 xml 檔案中的資訊匯總在一起。在一個檔案中,我有 ID 號和標題。在另一個檔案中,我有 ID 號和主題標題。基于共享 ID 號,我希望能夠在 XML 輸出中創建 2 個單獨的記錄,列出每個專案的相關主題標題。這是我所在的位置:
---XML 檔案 1---
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<Details Level="1">
<Section SectionNumber="0">
<Field Name="IDNUMBER1">
<Value>MMK.01922</Value>
</Field>
<Field Name="TITLE1">
<Value>This is the first title</Value>
</Field>
</Section>
</Details>
<Details Level="1">
<Section SectionNumber="0">
<Field Name="IDNUMBER1">
<Value>MMK.01984</Value>
</Field>
<Field Name="TITLE1">
<Value>Here is the second title</Value>
</Field>
</Section>
</Details>
</root>
---XML 檔案 2---
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mimsy_subject_data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<id_number>MMK.01922</id_number>
<subjects>
<thesaurus_lcna_geo1>Scotland</thesaurus_lcna_geo1>
<thesaurus_lcna_geo2>Abbotsford (Scotland)</thesaurus_lcna_geo2>
<thesaurus_lcna_name1>Scott, Walter, 1771-1832</thesaurus_lcna_name1>
<thesaurus_lcsh1>Scottish Borders (England and Scotland)</thesaurus_lcsh1>
</subjects>
</record>
<record>
<id_number>MMK.01984</id_number>
<subjects>
<thesaurus_lcna_geo1>Scotland</thesaurus_lcna_geo1>
<thesaurus_lcna_geo2>Edinburgh (Scotland)</thesaurus_lcna_geo2>
<thesaurus_lcna_corp1>Historic Royal Palaces (Great Britain)</thesaurus_lcna_corp1>
<thesaurus_lcsh1>Palaces</thesaurus_lcsh1>
<thesaurus_lcsh2>Landscapes</thesaurus_lcsh2>
<thesaurus_lcsh3>Buildings</thesaurus_lcsh3>
</subjects>
</record>
</mimsy_subject_data>
---XSLT---
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:str="http://exslt.org/strings"
xmlns:functx="http://www.functx.com" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:oai="http://www.openarchives.org/OAI/2.0/">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<!-- <xsl:template match="/"> -->
<xsl:template match="root">
<marc:collection>
<xsl:apply-templates/>
</marc:collection>
</xsl:template>
<xsl:template match="Details">
<xsl:apply-templates select="Section"/>
</xsl:template>
<xsl:template match="Section">
<xsl:param name = "subjectheading" select="document('mimsy_subject_data_export_tidied_for_SO.xml')/mimsy_subject_data/record" />
<marc:record>
<!-- BEGIN subjects-->
<xsl:for-each select=".">
<xsl:variable name="ID" select="Field[@Name = 'IDNUMBER1']/Value" />
<xsl:variable name="shcheck" select="$subjectheading[id_number=$ID]" />
<xsl:if test="$shcheck">
<marc:datafield tag="650" ind1=" " ind2=" ">
<marc:subfield code="a">
<xsl:copy-of select="$subjectheading/subjects"/>
</marc:subfield>
</marc:datafield>
</xsl:if>
</xsl:for-each>
</marc:record>
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>
---電流輸出---
<?xml version="1.0" encoding="UTF-8"?>
<marc:collection xmlns:str="http://exslt.org/strings"
xmlns:functx="http://www.functx.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:marc="http://www.loc.gov/MARC21/slim"
xmlns:oai="http://www.openarchives.org/OAI/2.0/">
<marc:record>
<marc:datafield tag="650" ind1=" " ind2=" ">
<marc:subfield code="a">
<subjects>
<thesaurus_lcna_geo1>Scotland</thesaurus_lcna_geo1>
<thesaurus_lcna_geo2>Abbotsford (Scotland)</thesaurus_lcna_geo2>
<thesaurus_lcna_name1>Scott, Walter, 1771-1832</thesaurus_lcna_name1>
<thesaurus_lcsh1>Scottish Borders (England and Scotland)</thesaurus_lcsh1>
</subjects>
<subjects>
<thesaurus_lcna_geo1>Scotland</thesaurus_lcna_geo1>
<thesaurus_lcna_geo2>Edinburgh (Scotland)</thesaurus_lcna_geo2>
<thesaurus_lcna_corp1>Historic Royal Palaces (Great Britain)</thesaurus_lcna_corp1>
<thesaurus_lcsh1>Palaces</thesaurus_lcsh1>
<thesaurus_lcsh2>Landscapes</thesaurus_lcsh2>
<thesaurus_lcsh3>Buildings</thesaurus_lcsh3>
</subjects>
</marc:subfield>
</marc:datafield>
</marc:record>
<marc:record>
<marc:datafield tag="650" ind1=" " ind2=" ">
<marc:subfield code="a">
<subjects>
<thesaurus_lcna_geo1>Scotland</thesaurus_lcna_geo1>
<thesaurus_lcna_geo2>Abbotsford (Scotland)</thesaurus_lcna_geo2>
<thesaurus_lcna_name1>Scott, Walter, 1771-1832</thesaurus_lcna_name1>
<thesaurus_lcsh1>Scottish Borders (England and Scotland)</thesaurus_lcsh1>
</subjects>
<subjects>
<thesaurus_lcna_geo1>Scotland</thesaurus_lcna_geo1>
<thesaurus_lcna_geo2>Edinburgh (Scotland)</thesaurus_lcna_geo2>
<thesaurus_lcna_corp1>Historic Royal Palaces (Great Britain)</thesaurus_lcna_corp1>
<thesaurus_lcsh1>Palaces</thesaurus_lcsh1>
<thesaurus_lcsh2>Landscapes</thesaurus_lcsh2>
<thesaurus_lcsh3>Buildings</thesaurus_lcsh3>
</subjects>
</marc:subfield>
</marc:datafield>
</marc:record>
</marc:collection>
---所需輸出---
<?xml version="1.0" encoding="UTF-8"?>
<marc:collection xmlns:str="http://exslt.org/strings"
xmlns:functx="http://www.functx.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:marc="http://www.loc.gov/MARC21/slim"
xmlns:oai="http://www.openarchives.org/OAI/2.0/">
<marc:record>
<marc:datafield tag="650" ind1=" " ind2=" ">
<marc:subfield code="a">
<subjects>
<thesaurus_lcna_geo1>Scotland</thesaurus_lcna_geo1>
<thesaurus_lcna_geo2>Abbotsford (Scotland)</thesaurus_lcna_geo2>
<thesaurus_lcna_name1>Scott, Walter, 1771-1832</thesaurus_lcna_name1>
<thesaurus_lcsh1>Scottish Borders (England and Scotland)</thesaurus_lcsh1>
</subjects>
</marc:subfield>
</marc:datafield>
</marc:record>
<marc:record>
<marc:datafield tag="650" ind1=" " ind2=" ">
<marc:subfield code="a">
<subjects>
<thesaurus_lcna_geo1>Scotland</thesaurus_lcna_geo1>
<thesaurus_lcna_geo2>Edinburgh (Scotland)</thesaurus_lcna_geo2>
<thesaurus_lcna_corp1>Historic Royal Palaces (Great Britain)</thesaurus_lcna_corp1>
<thesaurus_lcsh1>Palaces</thesaurus_lcsh1>
<thesaurus_lcsh2>Landscapes</thesaurus_lcsh2>
<thesaurus_lcsh3>Buildings</thesaurus_lcsh3>
</subjects>
</marc:subfield>
</marc:datafield>
</marc:record>
</marc:collection>
當前輸出創建 2 條記錄,其中包含 xml 檔案中列出的所有主題詞。我希望輸出有 2 條記錄,其中僅包含與每個 ID 號關聯的主題標題。我想這可能需要我使用另一個模板,但我只是不確定如何到達那里。非常感謝這里的任何幫助。提前謝謝了!
uj5u.com熱心網友回復:
為交叉參考宣告一個鍵,例如
<xsl:key name="id" match="record" use="id_number"/>
然后在模板中使用它
<xsl:template match="Section">
<xsl:variable name="referenced-record" select="key('id', Field[@Name = 'IDNUMBER1']/Value, doc('mimsy_subject_data_export_tidied_for_SO.xml'))"/>
并簡單地選擇/輸出您需要的主題,例如<xsl:copy-of select="$referenced-record/subjects"/>在該模板中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/492126.html
上一篇:Python XML檔案
