I have some xml data,which I need to index into solr core. For this I need to generate XSLT file for mapping my custom XML data to solr required format XML (1). Here my custom data:
<?xml version="1.0" encoding="UTF-8"?>
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>2021-06-24T06:02:01Z</responseDate>
<request verb="ListRecords" metadataPrefix="oai_dc" set="p15869coll19" from="2020-09-01" until="2020-09-30">http://digital.americanancestors.org/oai/oai.php</request>
<ListRecords>
<record>
<header>
<identifier>oai:digital.americanancestors.org:p15869coll19/17</identifier>
<datestamp>2020-09-21</datestamp>
<setSpec>p15869coll19</setSpec>
</header>
<metadata>
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:title>Papers of Abraham C. Ratshesky</dc:title>
<dc:identifier>P-586</dc:identifier>
<dc:relation>01</dc:relation>
<dc:subject>Halifax Explosion, Halifax, N.S. 1917; Massachusetts, General Court. Senate; American Red Cross. Boston Metropolitan Chapter</dc:subject>
<dc:description>Photographs; Morse Family</dc:description>
<dc:rights>Open access</dc:rights>
<dc:rights>User has an obligation to determine copyright or other use restrictions prior to publication or distribution. Please contact the archives at jhcreference@nehgs.org or 617-226-1245 for more information.</dc:rights>
<dc:language>English</dc:language>
<dc:source>Wyner Family Jewish Heritage Center, New England Historic Genealogical Society</dc:source>
<dc:identifier>http://digital.americanancestors.org/cdm/ref/collection/p15869coll19/id/17</dc:identifier>
</oai_dc:dc>
</metadata>
</record>
</ListRecords>
</OAI-PMH>
Is it available to generate XSL file for the above XML response? I have tried to generate with an online XML-XSLT generator but no success. Here what I tried: I am using this online generator. My input XMl is above.
My XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xpath-default-namespace="">
<xsl:output method="xml"
indent="yes"
encoding="UTF-8"/>
<xsl:template match="/">
<add>
<xsl:for-each select="OAI-PMH/ListRecords/record">
<doc>
<field name="id">
<xsl:value-of select="header/identifier"/>
</field>
<field name="ss_title">
<xsl:value-of select="metadata/oai_dc/title"/>
</field>
<field name="ss_relation">
<xsl:value-of select="metadata/oai_dc/dc:relation"/>
</field>
<field name="ss_description">
<xsl:value-of select="metadata/oai_dc:dc/dc:description"/>
</field>
</doc>
</xsl:for-each>
</add>
</xsl:template>
</xsl:transform>
Desired output:
<add>
<doc>
<field name="id">oai:digital.americanancestors.org:p15869coll19/17 </field>
<field name="ss_title">Papers of Abraham C. Ratshesky</field>
<field name="ss_relation"> 01</field>
<field name="ss_description">Photographs; Morse Family</field>
</doc>
</add>
Thanks.
Your XML uses some namespaces, which your stylesheet does not take into account.
Instead of:
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xpath-default-namespace="">
try:
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xpath-default-namespace="http://www.openarchives.org/OAI/2.0/"
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
exclude-result-prefixes="oai_dc dc">
You also need to replace:
<xsl:value-of select="metadata/oai_dc/title"/>
with:
<xsl:value-of select="metadata/oai_dc:dc/dc:title"/>
and make a similar correction to the value of ss_relation
.