我在寫一個xslt樣式表,將MARC-xml記錄轉換爲FGDC-xml元數據。很多MARC字段在最後(句號,冒號,逗號等)都有多餘的標點符號,我想刪除它們。儘管如此,我不想刪除全部標點符號。我的想法是編寫一個如果聲明和測試如果字段結束與指定的字符,然後將其刪除,但我不知道:1)如果這是一個好方法,2)如何指定該模板處理。xslt刪除結尾標點符號
編輯我的XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:marc="http://www.loc.gov/MARC21/slim" >
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="marc:collection/marc:record">
<xsl:result-document method="xml" href="banana_{marc:controlfield[@tag=001]}.xml">
<metadata>
<xsl:apply-templates select="self::marc:record"/>
</metadata>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
<xsl:template match="marc:record">
<pubinfo>
<pubplace><xsl:value-of select="marc:datafield[@tag=260]/marc:subfield[@code='a']"/></pubplace>
<publish><xsl:value-of select="marc:datafield[@tag=260]/marc:subfield[@code='b']" /></publish>
</pubinfo>
</xsl:template>
</xsl:stylesheet>
這裏是我的xml文檔(或至少它的代表性部分):
<?xml version="1.0" encoding="UTF-8"?>
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
<marc:record>
<marc:leader>01502cfm a2200313 a 4500</marc:leader>
<marc:controlfield tag="001">7943586</marc:controlfield>
<marc:datafield tag="260" ind1=" " ind2=" ">
<marc:subfield code="a">[S.l. :</marc:subfield>
<marc:subfield code="b">s.n. ,</marc:subfield>
<marc:subfield code="c">18--]</marc:subfield>
</marc:datafield>
</marc:record>
<marc:record>
<marc:leader>01290cem a2200313 a 4500</marc:leader>
<marc:controlfield tag="001">8108664</marc:controlfield>
<marc:datafield tag="260" ind1=" " ind2=" ">
<marc:subfield code="a">Torino :</marc:subfield>
<marc:subfield code="b">Editore Gio. Batt. Maggi ,</marc:subfield>
<marc:subfield code="c">1863.</marc:subfield>
</marc:datafield>
</marc:record>
</marc:collection>
「不知道放在這裏?」 'substring(1,string-length(marc:datafield [@ tag = 260]/marc:subfield [@ code ='b']) - 1)'工作嗎? – Pawel
我會盡力......但首先我想我的測試語句的語法錯誤,但是,這阻止了正確編譯樣式表。我得到錯誤:「在令牌開始的意外冒號」 –
好吧,我想我找到了「意外冒號...」的錯誤,現在我有:''。請原諒我,如果這是一個愚蠢的問題@Pawel,但我應該在你的建議的東西附上一行嗎?我試圖插入它,它只返回一個空標籤。 –