Sandy
Sandy

Reputation: 27

pull data from 2 xml files into third file

I'm trying to create a spreadsheet/delimited text file that pulls data from 2 XML files based on file name using XSLT 2.0 (using Saxon-PE 9.4.0.3 in Oxygen to do the transforms).

File 1 (main data file), WMS_Arabic_0006_mrc_test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:tei="http://www.tei-c.org/ns/1.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
   <marc:record>
      <marc:leader>00000ntm a22000002a 4500</marc:leader>
      <marc:datafield ind2=" " ind1=" " tag="699">
         <marc:subfield code="a">WMS Arabic 6</marc:subfield>
      </marc:datafield>
      <marc:datafield ind2=" " ind1=" " tag="040">
         <marc:subfield code="b">ara</marc:subfield>
      </marc:datafield>
   </marc:record>
</marc:collection>

File 2 (I want to add selected fields in this file), WMS_Arabic_0006_tei_test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<tei:TEI xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:marc="http://www.loc.gov/MARC21/slim"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <tei:teiHeader>
      <tei:fileDesc>
         <tei:titleStmt>
            <tei:title>Library</tei:title>
         </tei:titleStmt>
         <tei:publicationStmt>
            <tei:p>Library</tei:p>
         </tei:publicationStmt>
         <tei:sourceDesc>
            <tei:p>Born Digital</tei:p>
         </tei:sourceDesc>
      </tei:fileDesc>
   </tei:teiHeader>
   <tei:text>
      <tei:body>
         <tei:div>
            <tei:msDesc xml:lang="eng-Latn" xml:id="mWMSArabic6">
               <tei:msIdentifier>
                  <tei:collection type="main">Asian Collection</tei:collection>
                  <tei:collection type="sub">Iskandar</tei:collection>
                  <tei:idno>WMS Arabic 6</tei:idno>
               </tei:msIdentifier>
            </tei:msDesc>
         </tei:div>
      </tei:body>
   </tei:text>
</tei:TEI>

This is the XSLT file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
   xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:tei="http://www.tei-c.org/ns/1.0"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
   exclude-result-prefixes="xs" xmlns:wdl="http://project.wdl.org">
   <xsl:import href="../wdlfunclib.xsl"/>
   <xsl:strip-space elements="*"/>
   <!--Output as text-->
   <xsl:output encoding="UTF-8" method="text"/>
   <!-- Add field names on first line-->
   <xsl:template match="/">ID|Collection|
      <xsl:apply-templates/>
   </xsl:template>
   <xsl:template match="marc:record">
      <xsl:variable name="mrcFile_Name"><xsl:value-of select="tokenize(base-uri(.),'/')[last()]"
         /></xsl:variable>
      <xsl:variable name="teiFile_Name">WMS_Arabic_<xsl:value-of
            select="format-number(number(substring-after(substring-after(marc:datafield[@tag='699']/marc:subfield[@code='a'],' '),' ')),'0000')"
         />_tei.xml</xsl:variable>
      <xsl:variable name="teiPath"><xsl:value-of
            select="substring-before(base-uri(.),$mrcFile_Name)"/></xsl:variable>
      <xsl:variable name="teiFile_Location"><xsl:value-of select="$teiPath"/><xsl:value-of
            select="$teiFile_Name"/></xsl:variable>
      <xsl:variable name="myDoc"><xsl:value-of select="document($teiFile_Location)"/></xsl:variable>
      <!-- ID --><xsl:value-of
         select="normalize-space(marc:datafield[@tag='699']/marc:subfield[@code='a'])"
         />|<!-- Collection --><xsl:value-of
         select="$myDoc//tei:TEI/tei:text/tei:body/tei:div/tei:msDesc/tei:msIdentifier/tei:collection"
      />|<xsl:text>&#xA;</xsl:text>
   </xsl:template>
</xsl:stylesheet>

I seem to be having a problem with the Collection statement, specifically the path. If I use <xsl:value-of select="$myDoc//. I get all of the field values:

ID|Collection|
    WMS Arabic 6|LibraryLibraryBorn DigitalAsian CollectionIskandarWMS Arabic 6 LibraryLibraryBorn DigitalAsian CollectionIskandarWMS Arabic 6|

so I know it's matching the right document. When I try the whole path to the collection, I don't get anything. I've tried every variant I can think of but nothing gets any result.If anyone has any ideas, that would be greatly appreciated.

Thanks, Sandy

Upvotes: 0

Views: 59

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167401

Please use <xsl:variable name="mydoc" select="document($location)"/> instead of putting an xsl:value-of inside of the xsl:variable.

Upvotes: 1

Related Questions