xml - XSLT: How to force namespace in output child nodes -
i'm attempting implement oai-pmh harvesting xml using xslt 2.0 (i can version 3.0 if needs be) stated in oai-pmh spec problem getting "xsi" namespace in both oai-pmh tag , metadata tag schema requires. code works bit (i've removed bunch of stuff sake of brevity):
<?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" exclude-result-prefixes="xs" version="2.0" > <xsl:output indent="no" encoding="utf-8" method="xml" omit-xml- declaration="no" media-type="application/xml;charset=utf-8"/> <xsl:template match="/"> <xsl:apply-templates select="response" /> </xsl:template> <xsl:template match="response"> <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"> <xsl:apply-templates select="doc"/> </oai-pmh> </xsl:template> <xsl:template match="doc"> <record> <header> </header> <metadata> <oai_dc:dc xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:oai_dc="http://www.openarchives.org/oai/2.0/oai_dc/" 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/oai_dc/ http://www.openarchives.org/oai/2.0/oai_dc.xsd"> <xsl:text>call templates</xsltext> </metadata> </record> </xsl:template>
my output looks bit this:
<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 xmlns="">2015-09-30t16:47:19z</responsedate> <request xmlns="" verb="listrecords" metadataprefix="oai_dc" set="null" from="null" until="null">http://manchester.ac.uk/escholar/api/oai2</request> <listrecords xmlns=""> <record> <header> <identifier>oai:escholar.manchester.ac.uk:uk-ac-man-scw-1964</identifier> 2010-12-02t15:44:59.733z </header> <metadata> <oai_dc:dc xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:oai_dc="http://www.openarchives.org/oai/2.0/oai_dc/" xmlns="http://www.openarchives.org/oai/2.0/" xsi:schemalocation="http://www.openarchives.org/oai/2.0/oai_dc/ http://www.openarchives.org/oai/2.0/oai_dc.xsd"> </oai_dc:dc> </metadata> </record> </listrecords> </oai-pmh>
note the
xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
is missing oai_dc:dc tag. based upon oai-pmh spec/schema, needs there. can me resolve please?
i can tell you rid of xmlns=""
putting xmlns="http://www.openarchives.org/oai/2.0/"
on root of stylesheet. xmlns:xsi
namespace declaration, don't think can enforce xslt, in scope based on declaration on ancestor, therefore serializer not need add descendant element.
Comments
Post a Comment