4

我有一个非常奇怪的问题。我有在 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 个以上的术语,我无法弄清楚为什么第二个术语会被跳过。这就是我希望你帮助解决的问题。

我正在使用 XSL 1.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 字段是正确的。以下3个都缺少第二个术语“统计”。这只是一个示例,并且已经用不同的术语、不同的术语排序和/或不同数量的术语进行了复制。我认为问题出在我展示的 XSL 代码中,因为这是代码中唯一会影响我提供的示例的部分。如果没有人在 XSL 片段中发现任何错误,也许有人可以查看完整的 XSL。

更新:这是所有文件的链接(https://drive.google.com/folderview?id=0B647OE0WvD5-RFFPMjhqSjk3cVE&usp=sharing)。这包括整个 XSL 和 XML、一个被导入的附加 XSL、生成的输出 MRC 文件和一个 TXT 版本的 MRC 文件以便于查看。

4

1 回答 1

0

我会改变这个:

<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 在您认为的“-”之后开始。

于 2020-07-16T01:13:28.190 回答