<!--* 
<!DOCTYPE xsl:stylesheet [
*-->
<!DOCTYPE xsl:stylesheet PUBLIC 'http://www.w3.org/1999/XSL/Transform'
      '/SGML/Public/W3C/xslt10.dtd' [
<!ATTLIST xsl:stylesheet
  xmlns:oai    CDATA #IMPLIED
  xmlns:oai_dc CDATA #IMPLIED
  xmlns:dc     CDATA #IMPLIED
  xmlns:r      CDATA #IMPLIED
  xmlns:cc     CDATA #IMPLIED
  xmlns:rdf    CDATA #IMPLIED
  xmlns:p      CDATA #IMPLIED
  xmlns:xsi    CDATA #IMPLIED
>

<!ENTITY nl "&#xA;">
<!ENTITY txtnl '<xsl:text xmlns:xsl="http://www.w3.org/1999/XSL/Transform">&nl;</xsl:text>'>

]>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:oai="http://www.openarchives.org/OAI/2.0/" 
 xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" 
 xmlns:dc="http://purl.org/dc/elements/1.1/" 
 xmlns:r="http://www.openarchives.org/OAI/2.0/rights/"  
 xmlns:cc="http://web.resource.org/cc/" 
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:p="http://www.openarchives.org/OAI/2.0/provenance"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>

 <!--* A stylesheet to translate from a record in OAI (Open Archive 
     * Initiative) format with Creative Commons license information
     * into RDF.
     * 
     * Some general framing assumptions: (These may or may not apply in a
     * more realistic environment; we aren't familiar enough with 
     * actual OAI practice to know.  Modify to suit your situation.)
     * 
     *  - Each oai:OAI-PMH element presents us with a bibliographic
     *    description, some licensing information, metadata about the
     *    OAI request which elicited the data and the server which
     *    provided it, and possibly some other stuff.
     *    (On second thought, the unit of processing should surely 
     *    be the oai:record element, not OAI-PMH.  Or are they 1:1?)
     *    
     *  - The only information we're currently interested in capturing
     *    in our output RDF graph is the bibliographic information,
     *    the licensing information, and the link between them.
     * 
     *  - There may be more than one OAI-PMH element in the input document;
     *    if there are, we want to process all of them.
     * 
     *  - We want to produce one output graph, which we'll express using
     *    one rdf:RDF element.  It should contain zero or more bibliographic
     *    descriptions tagged as rdf:Description containing Dublin Core
     *    metadata, zero or more CC license descriptions, and links
     *    between them.
     * 
     * Some less general assumptions / beliefs / guesses:
     * 
     * - The license information in the sample OAI record describes
     *   licensing terms for the bibliographic item (the article about
     *   elephants), not for the OAI data (the description of the 
     *   article about elephants).  The documentation is kind of hazy.
     * 
     * - The provenance information in the sample OAI record describes
     *   the origin of the OAI data (the description of the 
     *   article about elephants), not the origin of the bibliographic
     *   item described (a particular copy of the article about
     *   elephants).  The documentation is kind of hazy.
     * 
     * - The bibliographic item is uniquely identified by one or more
     *   of the identifiers given in
     * 
     *      . the value of the oai:request element
     *
     *      . the 'identifier' attribute on the 'oai:request' element,
     *        which might plausibly be an identifier either for the
     *        bibliographic item or for the bibliographic record; in
     *        the latter case it might be used metonymically for the
     *        item.  (Or perhaps its an identifier for the request 
     *        itself, for billing or authorization purposes?)
     * 
     *      . the 'oai:identifier' element in the 'oai:header' element
     *        in the 'oai:record' element returned by the server as
     *        the child of oai:GetRecord.  Like the preceding, this 
     *        might plausibly be an identifier either for the
     *        bibliographic item or for the bibliographic record. In
     *        the latter case it might be used metonymically for the
     *        item; in either case, why is the value in the sample
     *        not the same as the value of the identifier requested?
     *        Unless oai:request/@identifier is not the identifier of
     *        the record requested?  In which case, how does the server
     *        know what record to return?
     * 
     *      . the 'p:identifier' element in the 'p:originDescription' element
     *        in the 'p:provenance' element in the 'oai:about' element in
     *        the 'oai:record' returned by the server as the child of 
     *        oai:GetRecord.  If this is an identifier of the bibliographic
     *        record or of the bibliographic item, it's puzzling that
     *        it is not the same as any other identifier which might 
     *        identify either.  It might be an identifier for the provenance
     *        information itself, although in that case one wonders 
     *        what information about provenance is actually being
     *        provided.
     * 
     *   For now, the stylesheet is written to use the first of these as
     *   the identifier for the bibliographic item whose licensing terms are
     *   being captured.
     * 
     * - Any oai:record we find is of interest, whether its parent is 
     *   oai:GetRecord or some other verb.
     * 
     * - Any oai:record we find is of interest, whether its parent is 
     *   oai:GetRecord or some other verb.
     *
     * - The bibliographic information we're interested in will always be
     *   located at oai:OAI-PMH/oai:*/oai:record/oai:metadata/dc:dc/*
     * 
     * - The licensing information we're interested in will always be
     *   located at oai:OAI-PMH/oai:*/oai:record/oai:about/r:rights
     *   /r:rightsDefinition/rdf:RDF/cc:License.
     *
     * - The licensing information we're interested in does not conflict
     *   with, but can usefully coexist with, whatever is conveyed by
     *   the dc:rights element in the bibliographic information.
     * 
     *-->

 <!--* Emit one RDF graph for this input document *-->
 <xsl:template match="/">
  <xsl:element name="rdf:RDF">&txtnl;
   <!--* fill out the graph by processing every OAI-PMH element
       * that contains an oai:record element.
       *-->
   <xsl:apply-templates select="//oai:OAI-PMH[//oai:record]"/>
  </xsl:element>
 </xsl:template>

 <!--* For each OAI-PMH element, emit one rdf:Description with bibliographic
     * information, and one License element with licensing information.
     * We make no effort to avoid duplicate License elements.  (The whole
     * thing is redundant with the RDF at the CC site anyway.)
     *-->
 <xsl:template match="oai:OAI-PMH">
  <!--* First, the bibliographic info. *-->
  <xsl:element name="rdf:Description">
   <!--* N.B. we don't actually know which identifier to use for rdf:about *-->
   <xsl:attribute name="rdf:about"><xsl:value-of select="./oai:request"/></xsl:attribute>
   
   &txtnl;
   <!--* within the rdf:Description, first copy the bibliographic description *-->
   <xsl:apply-templates select="./oai:*/oai:record/oai:metadata/oai_dc:dc/*" 
    mode="copy"/>

   <!--* Then add a link to the license.  Let's handle the case that there
       * might be more than one License around, and handle all of them.  *-->
   <xsl:apply-templates 
    select="./oai:*/oai:record/oai:about/r:rights/r:rightsDefinition/rdf:RDF/cc:License" 
    mode="license_link"/>
  </xsl:element>&txtnl;
  
  <!--* Second, the license info. *-->
  <xsl:apply-templates     
   select="./oai:*/oai:record/oai:about/r:rights/r:rightsDefinition/rdf:RDF/cc:License"
   mode="copy"/>
 </xsl:template>

 <xsl:template match="r:rights/r:rightsDefinition/rdf:RDF/cc:License" mode="license_link">
  <xsl:element name="cc:license">
   <xsl:attribute name="rdf:resource"><xsl:value-of select="@rdf:about"/></xsl:attribute>
  </xsl:element>&txtnl;
 </xsl:template>

 <xsl:template match="*" mode="copy">
  <xsl:copy-of select="."/>&txtnl;
 </xsl:template>

</xsl:stylesheet>
<!-- Keep this comment at the end of the file
Local variables:
mode: xml
sgml-default-dtd-file:"/SGML/Public/Emacs/xslt.ced"
sgml-omittag:t
sgml-shorttag:t
sgml-indent-data:t
sgml-indent-step:1
End:
-->

