I have an XML file and need to add a new element that contains values from a sibling element with XSLT. What I have is this:
<?xml version="1.0" encoding="UTF-8"?>
<collection
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"
xmlns="http://www.loc.gov/MARC21/slim">
<record>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="a">(OCoLC)ocm02255682</subfield>
</datafield>
<datafield tag="959" ind1=" " ind2=" ">
<subfield code="a">(MILdb)299946</subfield>
</datafield>
<datafield tag="959" ind1=" " ind2=" ">
<subfield code="a">(UIUdb)3899758</subfield>
</datafield>
</record>
And what I need is this:
<?xml version="1.0" encoding="UTF-8"?>
<collection
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"
xmlns="http://www.loc.gov/MARC21/slim">
<record>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="a">(OCoLC)ocm02255682</subfield>
</datafield>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="z">(UIU)Voyager3899758</subfield>
</datafield>
<datafield tag="959" ind1=" " ind2=" ">
<subfield code="a">(MILdb)299946</subfield>
</datafield>
<datafield tag="959" ind1=" " ind2=" ">
<subfield code="a">(UIUdb)3899758</subfield>
</datafield>
</record>
I've been working at it for a few hours with no meaningful output. Any help would be appreciated.
Here is what I have so far. This is the first XSLT I've tried to write, and I not sure if I'm on the right track. The output has the new field (but with namespaces for some reason), and does not include the value from the 959 subfield a element.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:marc="http://www.loc.gov/MARC21/slim"
version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="marc:record">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="z">(UIU)Voyager
<xsl:value-of select="marc:datafield[@tag=959]/marc:subfield[@code='a']"/>
</subfield>
</datafield>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>