Hi all this question is related to this: xsl get element values from another node tree But this time I have a working xslt.
I am currently working on the following xml:
<record>
<leader>01877nz a2200433o 4500</leader>
<controlfield tag="001">1</controlfield>
... (more controlfields tag 002 to 010)
<datafield tag="013" ind1=" " ind2=" ">
<subfield code="a">formerge</subfield>
</datafield>
... (more datafield tags, datafield tags are from 011 to 999)
<datafield tag="150" ind1=" " ind2=" ">
<subfield code="a">Borneo</subfield>
</datafield>
... (more datafield tags, datafield tags are from 011 to 999)
<datafield tag="550" ind1=" " ind2=" ">
<subfield code="w">g</subfield>
<subfield code="a">South East Asia</subfield>
<subfield code="c">c_7260</subfield>
</datafield>
... (more datafield tags, datafield tags are from 011 to 999)
</record>
... (more records)
<record>
... (more records fields)
... (more records fields)
</record>
<record>
<leader>02462nz a2200553o 4500</leader>
<controlfield tag="001">2</controlfield>
... (more controlfields tag 002 to 010)
<datafield tag="013" ind1=" " ind2=" ">
<subfield code="a">formerge</subfield>
</datafield>
<datafield tag="035" ind1=" " ind2=" ">
<subfield code="a">c_7260</subfield>
</datafield>
... (more datafield tags, datafield tags are from 011 to 999)
<datafield tag="151" ind1=" " ind2=" ">
<subfield code="a">South East Asia</subfield>
</datafield>
... (more datafield tags, datafield tags are from 011 to 999)
</record>
I have the following xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="marc">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:key name="term" match="//datafield[@tag='151'][subfield[@code='a']]" use="." />
<xsl:template match="//datafield[@tag='151'][subfield[@code='a']]">
<xsl:variable name="t550a" select="//datafield[@tag='550'][subfield[@code='a']]" />
<xsl:for-each select="key('term','$550a')">
<xsl:value-of select="//controlfield[@tag='001']" />
</xsl:for-each>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
With this, I created an index of all 151 through keys (term). I also created a variable 't550a'. Through the keys function, I match the 550a tags (datafield tag="550" subfield code="a") with term key. And then get the value of controlfield tag 001 of that key. I also wanted to get all the nodes of my xml thus the "xsl:copy". With the xslt I have, it seems that datafield tag 151 is being removed.
I wanted to get in 550 field the following:
... (other fields omitted)
<datafield tag="550" ind1=" " ind2=" ">
<subfield code="w">g</subfield>
<subfield code="a">South East Asia</subfield>
<subfield code="c">c_7260</subfield>
<subfield code="0">2</subfield>
</datafield>
... (other fields omitted)
<datafield tag="550" ind1=" " ind2=" ">
<subfield code="w">h</subfield>
<subfield code="a">Borneo</subfield>
<subfield code="c">c_1017</subfield>
<subfield code="0">1</subfield>
</datafield>
So 550 subfield a South East Asia will have additional subfield 0 with value 2, which is based from the controlfield 001 of 151 subfield a South East Asia. And also 550 subfield a Borneo will have additional subfield 0 with value 1, which is based from the controlfield 001 of 151 subfield a Borneo.
Can somebody lead me to doing this correctly. Thanks!