XSL Migration from EAD to MARC Skips Second Subject Term

I have a very strange problem. I have EAD encoded XML documents that I convert to MARC entries for the library directory. There is a section of the EAD document that looks like this:

    <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>

What makes the code right, pulls out each element / topic and creates a MARC field for each of them, and each term, separated by a "-", is placed in a separate subfield (either a, x, y, or whatever).

The code does this correctly if there are 1-3 members in one element, but if there are 4 or more terms, the second term is completely excluded, and the remaining members (starting from the third) are extracted properly. I cannot understand why the second term is skipped if there are 4+ conditions. This is what I would like your help to find out.

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>

tokenize, . , / . 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.

UPDATE. (https://drive.google.com/folderview?id=0B647OE0WvD5-RFFPMjhqSjk3cVE&usp=sharing) . XSL XML, XSL, , MRC TXT- MRC .

+4

Source: https://habr.com/ru/post/1542531/


All Articles