我真的很想在这里提供一些帮助。XSLT相对较新,并试图通过XSLT将2个xml文件中的信息汇总起来。在一个文件中,我有ID号和标题。在另一个文件中,我有ID号和主题标题。基于共享ID号,我希望能够在XML输出中创建两个单独的记录,列出每个项目的相关主题标题。以下是我所处的位置:
-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>当前输出创建两个记录,其中包含xml文件中列出的所有主题标题。我希望输出有两个记录,其中只包括与每个ID号码相关的主题标题。我认为这可能需要我使用另一个模板,但我只是不知道如何实现。这里的任何帮助都非常感谢。事先非常感谢!
发布于 2022-06-14 20:17:52
声明用于交叉引用的密钥。
<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://stackoverflow.com/questions/72622711
复制相似问题