This has got to be a very basic question, but I'm really struggling with a solution. From the following XML, I'm trying to extract the first instance only, when I have a match on the tag="099"
and the code="a"
attributes in a marc:datafield
node, and a marc:subfield
node, respectively
<?xml version="1.0" encoding="UTF-8" ?>
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim"
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:datafield tag="079" ind1=" " ind2=" ">
<marc:subfield code="a">79927839</marc:subfield>
</marc:datafield>
<marc:datafield tag="099" ind1=" " ind2=" ">
<marc:subfield code="a">940002</marc:subfield>
</marc:datafield>
<marc:datafield tag="099" ind1=" " ind2=" ">
<marc:subfield code="a">940002*</marc:subfield>
</marc:datafield>
<marc:datafield tag="099" ind1=" " ind2=" ">
<marc:subfield code="a">940002**</marc:subfield>
...
So, I'm trying to retrieve that first "940002". Using the following code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:marc="http://www.loc.gov/MARC21/slim">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/">
<!--identifier-->
<xsl:if test="/marc:collection/marc:record/marc:datafield/@tag='099'">
<xsl:element name="dc:identifier">
<xsl:if test="position()=1">
<xsl:value-of select="/marc:collection/marc:record/marc:datafield/marc:subfield/@code='a'"/>
</xsl:if>
</xsl:element>
</xsl:if>
...
However, what I'm getting is:
<?xml version="1.0" encoding="UTF-8"?>
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:marc="http://www.loc.gov/MARC21/slim">
<dc:identifier>true</dc:identifier>
...
Instead of the desired:
<?xml version="1.0" encoding="UTF-8"?>
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:marc="http://www.loc.gov/MARC21/slim">
<dc:identifier>940002</dc:identifier>
...
I'm guessing that it's got to be an Xpath issue, but... Any leads would be appreciated.
Thanks