<?xml version="1.0" encoding="UTF-8"?>
<!-- - - - - - - - - - -
Style sheet makes a copy of a DDI codebook and 
prefixes every attribute "ID" with the IDNo of the study.

joachim wackerow, wackerow@zuma-mannheim.de, 2004-05-10

-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output doctype-system="http://www.icpsr.umich.edu/DDI/Version2-0.dtd"/>
  <!-- - - - - - - - - - - -->
  <xsl:variable name="idno">
    <xsl:choose>
      <xsl:when test="/codeBook/stdyDscr/citation/titlStmt/IDNo">
        <xsl:value-of select="/codeBook/stdyDscr/citation/titlStmt/IDNo"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>
          <xsl:text>Error: Study "</xsl:text>
          <xsl:value-of select="/codeBook/stdyDscr/citation/titlStmt/titl"/>
          <xsl:text>" has no IDNo! </xsl:text>
        </xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <!-- - - - - - - - - - -
  Identity transformation according
  http://www.w3.org/TR/xslt#copying
  -->
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  <!-- - - - - - - - - - -
  template to prefix every attribute "ID" with the IDNo of the study
  -->
  <xsl:template match="@ID">
    <xsl:attribute name="{name(.)}">
      <xsl:value-of select="$idno"/>
      <xsl:text>_</xsl:text>
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <!-- - - - - - - - - - - -->
</xsl:stylesheet>
