> From: Code for Libraries [mailto:[EMAIL PROTECTED] On
> Behalf Of Hickey,Thom
> Sent: 10 February, 2006 14:19
> To: [email protected]
> Subject: [CODE4LIB] XSLT for LCCNs
>
> Anyone have some XSLT that will take arbitrary LCCN's as they
> are stored in MARC and transform them into a nicely
> hyphenated string for display (like in the errol in my signature)?
>
> --http://errol.oclc.org/laf/n82-54463.html

How about:

<xsl:transform version="2.0"
  exclude-result-prefixes="marc xsl"
  xmlns:marc="http://www.loc.gov/MARC21/slim";
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>

    <xsl:output method="text" version="1.0"
      media-type="text/plain" encoding="utf-8"
      omit-xml-declaration="yes" indent="no"
    />

    <xsl:strip-space elements="*"/>

    <xsl:template name="Root" match="/">

      <xsl:for-each select="//marc:record">

        <xsl:variable name="LCCN.record" select="marc:[EMAIL PROTECTED] = 
'010']/marc:[EMAIL PROTECTED] = 'a']"/>

        <xsl:variable name="LCCN.nospace" select="translate($LCCN.record, ' ', 
'')"/>
        <xsl:variable name="LCCN.length" select="string-length($LCCN.nospace)"/>

        <xsl:variable name="LCCN.display" 
select="concat(substring($LCCN.nospace, 1, $LCCN.length - 6), '-', 
substring($LCCN.nospace, $LCCN.length - 5))"/>

        <xsl:value-of select="concat('&#10;', $LCCN.display)"/>

      </xsl:for-each>

      <xsl:value-of select="string('&#10;')"/>

    </xsl:template>

</xsl:transform>


With the XML:

<?xml version="1.0" encoding="utf-8"?>

<collection xmlns="http://www.loc.gov/MARC21/slim"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://www.loc.gov/MARC21/slim 
http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd";>

  <record>
    <datafield tag="010" ind1=" " ind2=" ">
      <subfield code="a">sj 00001253 </subfield>
    </datafield>
  </record>

  <record>
    <datafield tag="010" ind1=" " ind2=" ">
      <subfield code="a">sj2005001188</subfield>
    </datafield>
  </record>

</collection>


Andy.

Reply via email to