gpt4 book ai didi

xslt 删除结束标点符号

转载 作者:行者123 更新时间:2023-12-03 22:16:50 27 4
gpt4 key购买 nike

我正在编写一个 xslt 样式表来将 MARC-xml 记录转换为 FGDC-xml 元数据。许多 MARC 字段的末尾都有多余的标点符号(句号、冒号、逗号等),我想将其删除。不过,我不想从行中删除所有标点符号。我的想法是编写一个带有 if 语句的模板并测试该字段是否以指定字符结尾,然后将其删除,但我不确定:1)这是否是一个好方法,以及 2)如何指定该过程。

已编辑 我的 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>

最佳答案

ends-with()接受一个简单的字符串,而不是一个正则表达式。这就是您遇到以下问题的原因:

ends-with(marc:datafield[@tag=260]/marc:subfield[@code='b'],'.|:|,')

如果你想使用正则表达式,那么使用 matches() :
marc:datafield[@tag=260]/marc:subfield[@code='b']/matches(.,'^.*[\.:,]$')

并删除使用 replace() :
replace('Ends with punctuation.', '^(.*)[\.:,]$', '$1')
=>
Ends with punctuation

仅在每个节点上执行替换而不是首先使用 if 进行测试也可能更简单,因为不匹配的情况不会进行替换,这似乎是您想要的行为。

关于xslt 删除结束标点符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13367509/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com