我有个很奇怪的问题。我有用EAD编码的XML文档,我正在将这些文档转换为用于库目录的MARC记录。EAD文档中有一节如下所示:
<controlaccess>
<list type="simple">
<item><subject encodinganalog="650" source="lcsh">Prisons -- History -- 19th century</subject></item>
<item><subject encodinganalog="650" source="lcsh">Prisons -- Statistics -- History -- 19th century</subject></item>
<item><subject encodinganalog="650" source="lcsh">Prisons -- Statistics -- Extra term 1 -- History -- 19th century</subject></item>
<item><subject encodinganalog="650" source="lcsh">Prisons -- Statistics -- Extra term 1 -- Extra term 2 -- History -- 19th century</subject></item>
</list>
</controlaccess>代码正确的做法是提取每个项/主题并为每个条目创建一个MARC字段,每个由"--“分隔的术语被放入一个单独的子字段( a、x、y或其他)。
如果单个主题元素中有1-3个术语,代码就会正确地这样做,但是如果有4个或更多的术语,那么第二个术语就会被完全删除,其余的术语(从第三个术语开始)就会被正确地提取出来。我不知道为什么第二个学期会被跳过,如果有4+条款。这就是我希望你帮我弄明白的。
我使用的是XSL1.0,代码的主题部分如下所示。从主模板正确地调用参数。
<xsl:template name="subject_template">
<xsl:param name="string" />
<marc:datafield>
<xsl:choose>
<xsl:when test="contains($string, '--')!=0">
<xsl:variable name="tmp1" select="substring-before($string, '--')" />
<xsl:variable name="tmp2" select="substring-after($string, '--')" />
<marc:subfield code="a">
<xsl:value-of select="$tmp1" />
</marc:subfield>
<xsl:call-template name="subject_tokenize">
<xsl:with-param name="string" select="$tmp2" />
<xsl:with-param name="type" select="'x'" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<marc:subfield code="a">
<xsl:value-of select="$string" />
</marc:subfield>
</xsl:otherwise>
</xsl:choose>
</marc:datafield>
</xsl:template>下面是标记模板,它有数百行长。我试图只包括与我的问题有关的必要的内容。开头的4个变量(genx等)从一个庞大的术语列表中提取出来,以确定子字段代码应该是什么。
<xsl:template name="subject_tokenize">
<xsl:param name="string" />
<xsl:param name="type" />
<xsl:variable name="genx">
<xsl:call-template name="genx" />
</xsl:variable>
<xsl:variable name="geny">
<xsl:call-template name="geny" />
</xsl:variable>
<xsl:variable name="formlist">
<xsl:call-template name="formlist" />
</xsl:variable>
<xsl:variable name="geoglist">
<xsl:call-template name="geoglist" />
</xsl:variable>
<xsl:if test="contains($string, '--')!=0">
<xsl:variable name="str1" select="substring-before($string, '--')"/>
<xsl:variable name="str2" select="substring-after($string, '--')"/>
<xsl:if test="contains($str2, '--')!=0">
<xsl:variable name="newstr2" select="substring-after($str2, '--')"/>
<xsl:variable name="tmpvar" select="substring-before($str2, '--')"/>
<xsl:choose>
<xsl:when test="testsomething">
do stuff
</xsl:when>
<xsl:otherwise>
<xsl:if test="contains($geoglist, translate($str1, '.', ''))!=0">
<marc:subfield code="z">
<xsl:value-of select="$str1"/>
</marc:subfield>
<xsl:if
test="contains($formlist, translate(substring-before($str2, '--'), '.', ''))!=0">
<marc:subfield code="v">
<xsl:value-of select="substring-before($str2, '--')"/>
</marc:subfield>
</xsl:if>
<xsl:if
test="contains($geny, translate(substring-before($str2, '--'), '.', ''))!=0">
<marc:subfield code="y">
<xsl:value-of select="substring-before($str2, '--')"/>
</marc:subfield>
</xsl:if>
<xsl:if
test="contains($genx, translate(substring-before($str2, '--'), '.', ''))!=0">
<marc:subfield code="x">
<xsl:value-of select="substring-before($str2, '--')"/>
</marc:subfield>
</xsl:if>
<xsl:if
test="contains($formlist, translate(substring-before($str2, '--'), '.', ''))=0 and contains($genx, translate(substring-before($str2, '--'), '.', ''))=0 and contains($geny, translate(substring-before($str2, '--'), '.', ''))=0">
<marc:subfield code="z">
<xsl:value-of select="substring-before($str2, '--')"/>
</marc:subfield>
</xsl:if>
</xsl:if>
<xsl:if test="contains($formlist, translate($str1, '.', ''))!=0">
<marc:subfield code="v">
<xsl:value-of select="$str1"/>
</marc:subfield>
</xsl:if>
<xsl:if test="contains($geny, translate($str1, '.', ''))!=0">
<marc:subfield code="y">
<xsl:value-of select="$str1"/>
</marc:subfield>
</xsl:if>
<xsl:if
test="contains($formlist, translate($str1, '.', ''))=0 and contains($geny, translate($str1, '.', ''))!=0">
<marc:subfield code="x">
<xsl:value-of select="$str1"/>
</marc:subfield>
</xsl:if>
<xsl:if test="contains($geoglist, translate($str1, '.', ''))=0">
<xsl:if
test="contains($formlist, translate(substring-before($str2, '--'), '.', ''))!=0">
<marc:subfield code="v">
<xsl:value-of select="substring-before($str2, '--')"/>
</marc:subfield>
</xsl:if>
<xsl:if
test="contains($geny, translate(substring-before($str2, '--'), '.', ''))!=0">
<marc:subfield code="y">
<xsl:value-of select="substring-before($str2, '--')"/>
</marc:subfield>
</xsl:if>
<xsl:if
test="contains($geoglist, translate(substring-before($str2, '--'), '.', ''))!=0">
<marc:subfield code="z">
<xsl:value-of select="substring-before($str2, '--')"/>
</marc:subfield>
</xsl:if>
<xsl:if
test="contains($geoglist, translate(substring-before($str2, '--'), '.', ''))=0 and contains($geny, translate(substring-before($str2, '--'), '.', ''))=0 and contains($formlist, translate(substring-before($str2, '--'), '.', ''))=0">
<marc:subfield code="x">
<xsl:value-of select="substring-before($str2, '--')"/>
</marc:subfield>
</xsl:if>
</xsl:if>
<xsl:call-template name="subject_tokenize">
<xsl:with-param name="string" select="$newstr2"/>
<xsl:with-param name="type" select="'x'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>我的输出如下:
=650 \0$aPrisons $x History $x 19th century
=650 \0$aPrisons $x History $x 19th century
=650 \0$aPrisons $x Extra term 1 $x History $x 19th century
=650 \0$aPrisons $x Extra term 1 $x Extra term 2 $x History $x 19th century前650个字段是正确的。以下三个都错过了第二个学期,“统计”。这只是一个例子,已经被不同的术语、不同的术语排序和/或不同数量的术语所复制。我认为问题在于我展示的XSL代码,因为这是代码中唯一应该影响我提供的示例的部分。如果没有人在XSL片段中发现任何错误,也许有人可以查看完整的XSL。
UPDATE:这是指向所有文件的链接(https://drive.google.com/folderview?id=0B647OE0WvD5-RFFPMjhqSjk3cVE&usp=sharing)。这包括整个XSL和XML、一个额外的导入XSL、输出的MRC文件和一个TXT版本的MRC文件,以便于查看。
发布于 2020-07-16 01:13:28
我要改变这一点:
<xsl:variable name="str1" select="substring-before($string, '--')"/>
<xsl:variable name="str2" select="substring-after($string, '--')"/>对此:
<xsl:variable name="str1" select="substring-before($string, '--')"/>
<xsl:variable name="str2" select="substring-after($string, concat($str1,'--'))"/>这将确保str2在您认为的“--”之后启动。
https://stackoverflow.com/questions/23939533
复制相似问题