首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从EAD到MARC的XSL转换跨越第二个主题学期

从EAD到MARC的XSL转换跨越第二个主题学期
EN

Stack Overflow用户
提问于 2014-05-29 17:39:41
回答 1查看 135关注 0票数 4

我有个很奇怪的问题。我有用EAD编码的XML文档,我正在将这些文档转换为用于库目录的MARC记录。EAD文档中有一节如下所示:

代码语言:javascript
复制
    <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,代码的主题部分如下所示。从主模板正确地调用参数。

代码语言:javascript
复制
<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等)从一个庞大的术语列表中提取出来,以确定子字段代码应该是什么。

代码语言:javascript
复制
<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>

我的输出如下:

代码语言:javascript
复制
=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文件,以便于查看。

EN

回答 1

Stack Overflow用户

发布于 2020-07-16 01:13:28

我要改变这一点:

代码语言:javascript
复制
<xsl:variable name="str1" select="substring-before($string, '--')"/>
<xsl:variable name="str2" select="substring-after($string, '--')"/>

对此:

代码语言:javascript
复制
<xsl:variable name="str1" select="substring-before($string, '--')"/>
<xsl:variable name="str2" select="substring-after($string, concat($str1,'--'))"/>

这将确保str2在您认为的“--”之后启动。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23939533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档