Skip to content

Instantly share code, notes, and snippets.

@timathom
Last active July 9, 2025 12:46
Show Gist options
  • Save timathom/b83ce0992c18b30f462bff48f1d62e6e to your computer and use it in GitHub Desktop.
Save timathom/b83ce0992c18b30f462bff48f1d62e6e to your computer and use it in GitHub Desktop.
`no_linkage` normalization rule for generic names in Alma
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Identity transform -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Process the entire record -->
<xsl:template match="record">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<!-- Define authority check variables at record level -->
<xsl:variable name="has_lc_source" as="xs:boolean">
<xsl:sequence select="
some $_ in datafield[@tag = '040']/subfield[@code =
('a', 'd')]
satisfies contains($_, 'DLC')"/>
</xsl:variable>
<xsl:variable name="has_pcc" as="xs:boolean">
<xsl:sequence select="
some $_ in datafield[@tag = '042']/subfield[@code = 'a']
satisfies contains($_, 'pcc')"/>
</xsl:variable>
<xsl:variable name="has_lccopycat" as="xs:boolean">
<xsl:sequence select="
some $_ in datafield[@tag = '042']/subfield[@code = 'a']
satisfies contains($_, 'lccopycat')"/>
</xsl:variable>
<!-- Process all child nodes with authority context available -->
<xsl:apply-templates select="node()">
<xsl:with-param name="is_authoritative"
select="$has_lc_source or $has_pcc or $has_lccopycat"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!-- Process personal name fields -->
<xsl:template match="datafield[@tag = ('100', '600', '700', '800')]">
<xsl:param name="is_authoritative" as="xs:boolean"/>
<xsl:choose>
<!-- Check if field needs no_linkage -->
<xsl:when test="
subfield[@code = 'a'] and
not(subfield[@code = 'd']) and
not(subfield[@code = '9'][. = 'no_linkage']) and
not($is_authoritative)">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="subfield"/>
<subfield code="9">no_linkage</subfield>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<!-- Copy as-is -->
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="subfield"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment