我刚刚开始使用XSLT.我有一个带有多个记录的xml文档。我想取每个下面的值,并将其作为一个新元素插入到相应的元素中。不幸的是,我的XSLT获取了所有oai:标识符的值,并将其转储到每条记录的mods:标识符的值下,因为我不知道要使用哪个表达式。
这里是xml文档的一个片段。
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xip="http://www.tessella.com/XIP/v4"
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>2019-06-15T02:21:52Z</responseDate>
<request verb="ListRecords" metadataPrefix="MODS" from="2019-06-01T00:00:00Z"
until="2019-06-04T23:59:59Z">https://lac.preservica.com/OAI-PMH/</request>
<ListRecords>
<record>
<header>
**<identifier>oai:du:191f96fe-fcf7-4205-a6b0-980e74b51178</identifier>**
<datestamp>2019-06-04T22:42:33Z</datestamp>
</header>
<metadata>
<mods:mods xmlns:mods="http://www.loc.gov/mods/v3"
xmlns="http://www.loc.gov/mods/v3" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:local="http://www.loc.org/namespace" version="3.4">
<titleInfo>
<title>Cadre de surveillance</title>
</titleInfo>
<name type="corporate">
<namePart>Canada.</namePart>
<namePart>Agence de la consommation en matière financière du
Canada</namePart>
</name>
<typeOfResource>text</typeOfResource>
<genre authority="rdacontent/fre">texte</genre>
<originInfo>
<place>
<placeTerm authority="marccountry" type="code">onc</placeTerm>
</place>
<dateIssued encoding="marc">20182017</dateIssued>
<edition>Version finale révisée.</edition>
<issuance>monographic</issuance>
</originInfo>
<originInfo displayLabel="publisher">
<place>
<placeTerm type="text">Ottawa : </placeTerm>
</place>
....
**<identifier invalid="yes">9780660082752</identifier>**
....
</mods:mods>
</metadata>
<about>
<aboutRecord:aboutRecord
xmlns:aboutRecord="http://www.preservica.com/OAI-PMH/Extension"
xmlns="http://www.preservica.com/OAI-PMH/Extension">
<Identifier>oai:du:191f96fe-fcf7-4205-a6b0-980e74b51178</Identifier>
<CurrentVersion>0cb46171-b015-4ba1-bde8-4fd87f4c6cee</CurrentVersion>
<ChangeType>Created</ChangeType>
<XIP schemaURI="http://www.tessella.com/XIP/v4">
<xip:DeliverableUnit status="new">
...
</xip:CurrentVersion>
</xip:DeliverableUnit>
</XIP>
</aboutRecord:aboutRecord>
</about>
</record>
<record>
<header>
<identifier>oai:du:f0dbbd4c-ec70-40cd-bbb2-4b88926043fd</identifier>
<datestamp>2019-06-04T22:42:33Z</datestamp>
</header>
<metadata>
<mods:mods xmlns:mods="http://www.loc.gov/mods/v3"
xmlns="http://www.loc.gov/mods/v3" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:local="http://www.loc.org/namespace" version="3.4">
<titleInfo>
<title>Compréhension et sensibilisation aux commotions liées au sport, en
....XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mods="http://www.loc.gov/mods/v3"
xmlns:oai="http://www.openarchives.org/OAI/2.0/" xmlns:xip="http://www.tessella.com/XIP/v4"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd mods xip oai aboutRecord"
xmlns:aboutRecord="http://www.preservica.com/OAI-PMH/Extension"
xmlns="http://www.preservica.com/OAI-PMH/Extension" version="2.0">
<xsl:output method="xml" indent="yes"/>
<!-- Identity template. Copies everything -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Overide identity template to add a new identifier to the MODS identifier element -->
<xsl:template match="mods:mods/mods:identifier[1]">
<!-- Copy the existing elements -->
<xsl:copy>
<!-- And everything inside it -->
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
<!-- Add new node -->
<identifier type="preservation">
<xsl:value-of select="/oai:OAI-PMH/oai:ListRecords/oai:record/oai:header/oai:identifier"></xsl:value-of>
</identifier>
</xsl:template>预期结果将取值oai:标识符(:du:191f96fe-fcf7-4205-a6b0-980e74b51178),并将其作为相应的新mods:标识符插入,并对每条记录重复此过程。详情如下:
<identifier type="preservation">oai:du:191f96fe-fcf7-4205-a6b0-980e74b51178</identifier>的实际结果最终为:
<identifier xmlns="http://www.preservica.com/OAI-PMH/Extension" type="preservation">oai:du:191f96fe-fcf7-4205-a6b0-980e74b51178 oai:du:f0dbbd4c-ec70-40cd-bbb2-4b88926043fd oai:du:17010ebc-1fbc-47bb-96ab-5fb17f7171cb....发布于 2019-07-21 13:26:09
您可以得到这个名称空间,因为样式表在其根元素上声明了xmlns="http://www.preservica.com/OAI-PMH/Extension"。不清楚是否需要创建其他元素,如果不需要,只需取出它,否则使用
<!-- Add new node -->
<identifier xmlns="http://www.loc.gov/mods/v3" type="preservation">(您为identifier元素分别需要的任何名称空间,以及您抛入的所有数据,我都有点丢失了)。
至于引用相应的标识符,我认为您想要引用
<xsl:value-of select="ancestor::oai:record/oai:header/oai:identifier"/>https://stackoverflow.com/questions/57132381
复制相似问题