我试图使用XSLT2.0实现OAI-PMH获取XML (如果需要,我可以将版本提高到3.0 ),正如OAI-PMH规范中所述,我的问题是根据模式需要在OAI-PMH标记和元数据标记中获取"xsi“名称空间。目前,我的代码工作得有点像这样(为了简洁起见,我删除了一堆东西):
<?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 some templates</xsltext>
</metadata>
</record>
</xsl:template>我的输出看起来有点像这样:
<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>请注意,
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"在oai_dc:dc标记中丢失。但是基于OAI-PMH规范/模式,它需要存在。有人能帮我解决这个问题吗?
发布于 2015-09-30 16:13:55
我可以告诉您,通过将xmlns=""放在样式表的根目录上,您将摆脱所有的xmlns="http://www.openarchives.org/OAI/2.0/"。至于xmlns:xsi名称空间声明,我认为您不能使用XSLT强制执行它,因为它基于祖先的声明,因此序列化程序不需要将它添加到子代元素中。
发布于 2015-09-30 21:41:07
您所引用的规范确实说:“每个元数据部分都必须包含属性xmlns:xsi”。我认为唯一明智的解释方法是“前缀”"xsi“到名称空间"http://www.w3.org/2001/XMLSchema-instance”的名称空间绑定必须是每个元数据部分的作用域“。
如果规范使用DTD要求命名空间声明在特定元素上实际存在(就像某些DTD所做的那样),那么您就会遇到问题。但我没有看到任何证据表明这个规范使用了DTD。对于XSD模式,不可能说必须存在冗余的命名空间声明。
https://stackoverflow.com/questions/32870796
复制相似问题