<?xml version="1.0"?>
<!--
Copyright (c) 2000-2002 Carnegie Mellon University. All rights reserved.
Redistribution and use in source and binary forms, with or without   
modification, are permitted provided that the following conditions are met:
   
1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.  

3. The name "Carnegie Mellon University" must not be used to endorse or
   promote products derived from this software without prior written
   permission. For permission or any legal details, please contact:  
     Office of Technology Transfer
     Carnegie Mellon University
     5000 Forbes Avenue
     Pittsburgh, PA 15213-3890
     (412) 268-4387, fax: (412) 268-7395
     tech-transfer@andrew.cmu.edu

4. Redistributions of any form whatsoever must retain the following
   acknowledgment: "This product includes software developed by Computing
   Services at Carnegie Mellon University (http://www.cmu.edu/computing/)."

CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL,
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE  
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
-->
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:variable name="attrtypes" select="/dbidump/resultset[@table='attribute_types']/rows"/>
  <xsl:template match="row" mode="convert-attrtype">
    <xs:element name="{@name}">
      <xs:complexType>
        <xsl:if test="@value_has_string = 1">
          <xsl:choose>
            <xsl:when test="@value_has_action = 1">
              <xs:attribute name="string" type="xs:string" use="optional"/>
            </xsl:when>
            <xsl:otherwise>
              <xs:attribute name="string" type="xs:string" use="required"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:if>
        <xsl:if test="@value_has_number = 1">
          <xs:attribute name="number" type="xs:integer" use="optional"/>
        </xsl:if>
        <xsl:if test="@value_has_time = 1">
          <xs:attribute name="time" type="xs:integer" use="optional"/>
        </xsl:if>
        <xsl:if test="@value_has_range = 1 ">
          <xs:attribute name="range_start" type="xs:integer" use="optional"/>
          <xs:attribute name="range_end" type="xs:integer" use="optional"/>
        </xsl:if>
        <xsl:if test="@value_has_boolean = 1">
          <xs:attribute name="boolean" type="xs:boolean" use="optional"/>
        </xsl:if>
	<xsl:if test="@value_has_period = 1">
	  <xs:attribute name="weekday_start" type="xs:token" use="optional"/>
	  <xs:attribute name="weekday_end" type="xs:token" use="optional"/>
	  <xs:attribute name="time_start" type="xs:token" use="optional"/>
	  <xs:attribute name="time_end" type="xs:token" use="optional"/>
	  <xs:attribute name="month_start" type="xs:token" use="optional"/>
	  <xs:attribute name="month_end" type="xs:token" use="optional"/>
	  <xs:attribute name="monthday_start" type="xs:token" use="optional"/>
	  <xs:attribute name="monthday_end" type="xs:token" use="optional"/>
	  <xs:attribute name="monthweek_start" type="xs:token" use="optional"/>
	  <xs:attribute name="monthweek_end" type="xs:token" use="optional"/>
        </xsl:if>
        <xsl:if test="@value_has_action = 1">
          <xs:attribute name="action" type="xs:string" use="required"/>
        </xsl:if>
        <xsl:if test="@value_has_host = 1">
          <xs:attribute name="host" type="xs:string" use="optional"/>
        </xsl:if>
        <xsl:if test="@value_has_usergroup = 1">
          <xs:attribute name="user" type="xs:string" use="optional"/>
        </xsl:if>
      </xs:complexType>
    </xs:element>
  </xsl:template>
  <xsl:template match="resultset">
    <xsl:if test="@table='attribute_types'">
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        xmlns:tns="http://www.net.cmu.edu/netsage/xml/attributes"
        targetNamespace="http://www.net.cmu.edu/netsage/xml/attributes"
        elementFormDefault="qualified">
        <xsl:apply-templates mode="convert-attrtype"/>
      </xs:schema>
    </xsl:if>
  </xsl:template>
  
  </xsl:transform>

