Problem: Loading Part of XML-File in Variable
Posted: Wed Mar 18, 2020 6:28 pm
Hello all,
I'm having trouble loading parts of an XML-File from an interface in a variable and reuse that variable later.
Here's what I'm trying to do: I want to extraxt information from a SRU-interface from the German National Library DNB with an ID that matches a certain criteria
https://services.dnb.de/sru/authorities ... =118580604
If the ID matches in a record with datafield[tag='035'] and subfield[@code='a'], then copy the ancestor record-element, store it in a variable and extract data from the record.
The problem is, that the variable seems to be empty and I can't adress an element unless I force it with
Has anyone any idea why the namespace declaration gets lost when I want to use it in the variable? It worked in the template.
Any hints would be very much appreciated!
I'm having trouble loading parts of an XML-File from an interface in a variable and reuse that variable later.
Here's what I'm trying to do: I want to extraxt information from a SRU-interface from the German National Library DNB with an ID that matches a certain criteria
https://services.dnb.de/sru/authorities ... =118580604
If the ID matches in a record with datafield[tag='035'] and subfield[@code='a'], then copy the ancestor record-element, store it in a variable and extract data from the record.
Code: Select all
<xsl:transform version="3.0"
xmlns="http://MyDefaultNamespace"
xmlns:marc="http://www.loc.gov/MARC21/slim"
xmlns:sru="http://www.loc.gov/zing/srw/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="no" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:variable name="DataToExtract">
<xsl:call-template name="getInfoFromSRU">
<xsl:with-param name="id" select="'118580604'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="element">
<element>
<xsl:if test="$DataToExtract[normalize-space()]">
<xsl:value-of select="$DataToExtract/marc:datafield[@tag='100']/marc:subfield[@code='a']"/>
</xsl:if>
</element>
</xsl:variable>
<xsl:result-document method="xml" indent="no" encoding="UTF-8">
<record xmlns="http://MyDefaultNamespace"">
<xsl:copy-of select="$element"/>
</record>
</xsl:result-document>
</xsl:template>
<xsl:template name="getInfoFromSRU">
<xsl:param name="id"/>
<xsl:param name="url" select="'https://services.dnb.de/sru/authorities?version=1.1&operation=searchRetrieve&recordSchema=MARC21-xml&maximumRecords=100&query='"/>
<xsl:param name="URLsuffix"/>
<xsl:param name="nextRecordPosition"/>
<xsl:variable name="URLcomplete" select="doc(concat($url,$id,$URLsuffix,$nextRecordPosition))"/>
<xsl:choose>
<xsl:when test="$URLcomplete/sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData/marc:record[./marc:datafield[@tag='035']/marc:subfield[@code='a' and starts-with(.,'(DE-588)')] = concat('(DE-588)',$id)]">
<xsl:copy-of select="$URLcomplete/sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData/marc:record[./marc:datafield[@tag='035']/marc:subfield[@code='a' and starts-with(.,'(DE-588)')] = concat('(DE-588)',$id)]"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="getInfoFromSRU">
<xsl:with-param name="id" select="$id"/>
<xsl:with-param name="url" select="$url"/>
<xsl:with-param name="URLsuffix" select="'&startRecord='"/>
<xsl:with-param name="nextRecordPosition" select="$URLcomplete/sru:searchRetrieveResponse/sru:nextRecordPosition"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:transform>
Code: Select all
<xsl:value-of select="$DataToExtract//*[name()='datafield' and @tag='100']/*[name()='subfield' and @code='a']/text()"/>
Any hints would be very much appreciated!