Print

Print


Since I'm big on parsing out data where possible, and MARC/MARCXML does
not parses names, I came up with the following XSLT 2 stylesheet to do
this.  Currently it will only handle a name of the form "Family,
Given."  Can someone give some more info on how coding of names is
handled in MARC?  For example, what about terms of address, things like
Jr, II, etc.?

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>

<xsl:template match="name">
   <xsl:choose>
     <xsl:when test="@type='personal'">
       <name type="personal">
        <xsl:apply-templates/>
       </name>
     </xsl:when>
     <xsl:when test="@type='corporate'">
       <name type="corporate">
        <xsl:apply-templates/>
       </name>
     </xsl:when>
     <xsl:when test="@type='conference'">
       <name type="conference">
        <xsl:apply-templates/>
       </name>
     </xsl:when>
     <xsl:otherwise>
       <name>
        <xsl:apply-templates/>
       </name>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template match="namePart">
   <xsl:variable name="elValue" select="."/>

   <xsl:analyze-string select="$elValue" regex="\s*(.*)\s*,\s*(.*)\s*">

     <xsl:matching-substring>
       <namePart type="given"><xsl:value-of
select="regex-group(2)"/></namePart>
       <namePart type="family"><xsl:value-of
select="regex-group(1)"/></namePart>
     </xsl:matching-substring>

     <xsl:non-matching-substring>
       <namePart>
        <xsl:value-of select="$elValue"/>
       </namePart>
     </xsl:non-matching-substring>

   </xsl:analyze-string>

</xsl:template>
</xsl:stylesheet>