<!-- 
Created by: 
$Id: HR.xsl,v 1.3 2004/02/10 01:11:18 eric Exp $ -->

<xsl:transform version="1.0"
 xmlns:per="http://example.com/Personel"
 xmlns:addr="http://example.com/Address"
 xmlns:a="http://www.w3.org/2002/12/26-XMLgrammer2RDFdb/annot#"
 xmlns:foaf="http://foaf.org/#"
 xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <!-- You must manually set your output library here 'cause
       XSLT won't allow parameter definition before an import.
       I would prefer
xsltproc - -stringparam output RdfXStoNTriple.xsl RDFXMLtoRdfXS.xsl test.rdf
  -->
  <xsl:import href="RdfXStoNTriple.xsl"/>
  <xsl:output method="text"/>

  <xsl:param name="baseURI" select="'-- need base URI parameter --'"/>  <xsl:param name="foaf" select="'http://xmlns.com/foaf/0.1/'"/>  <xsl:param name="hr" select="'http://example.com/HR#'"/>  <xsl:param name="addr" select="'http://example.com/Addr#'"/>  <xsl:param name="Given" select="concat('&lt;', $foaf, 'givenname&gt;')"/>  <xsl:param name="Family" select="concat('&lt;', $foaf, 'familyname&gt;')"/>  <xsl:param name="Email" select="concat('&lt;', $foaf, 'email&gt;')"/>  <xsl:param name="Addr" select="concat('&lt;', $hr, 'addr&gt;')"/>  <xsl:param name="Manager" select="concat('&lt;', $hr, 'manager&gt;')"/>  <xsl:param name="Grunt" select="concat('&lt;', $hr, 'grunt&gt;')"/>  <xsl:param name="Location" select="concat('&lt;', $hr, 'location&gt;')"/>  <xsl:param name="StreetAddr" select="concat('&lt;', $addr, 'streetAddr&gt;')"/>
<!-- xsl:value-of select="concat('/ at:', local-name(.), '&#xA;')"/ -->

  <xsl:template match="/">
    <xsl:call-template name="startDocument"/>
    <xsl:call-template name="root">
      <xsl:with-param name="__PATH" select="'root'"/>
    </xsl:call-template>
    <xsl:call-template name="endDocument"/>
  </xsl:template>

  <xsl:template name="root">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test=".=/">

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected root element'"/>
          <xsl:with-param name="expected" select="'/'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <!-- call productions for nested elements -->
    <xsl:for-each select="*">
      <xsl:choose>
        <xsl:when test="self::per:Personel">
          <xsl:call-template name="Personel_0">
            <xsl:with-param name="__PATH" select="'doc Personel'"/>
            <xsl:with-param name="subject" select="$subject"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="error">
            <xsl:with-param name="hint" select="'no matching root production'"/>
            <xsl:with-param name="expected" select="'/'"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>

  </xsl:template><!-- end root -->

  <!-- root: doc Personel -->
  <xsl:template name="Personel_0">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test="self::per:Personel">

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected Personel_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:Personel&gt; '"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <!-- call productions for nested elements -->
    <xsl:for-each select="*">
      <xsl:choose>
        <xsl:when test="self::per:Person">
          <xsl:call-template name="Person_0">
            <xsl:with-param name="__PATH" select="'PersonelElts Person'"/>
            <xsl:with-param name="subject" select="$subject"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="self::per:Departement">
          <xsl:call-template name="Department_0">
            <xsl:with-param name="__PATH" select="'PersonelElts Department'"/>
            <xsl:with-param name="subject" select="$subject"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="self::addr:Address">
          <xsl:call-template name="Address_0">
            <xsl:with-param name="__PATH" select="'PersonelElts Address'"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="error">
            <xsl:with-param name="hint" select="'no matching Personel_0 production'"/>
            <xsl:with-param name="expected" select="'&lt;per:Personel&gt; '"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>

  </xsl:template><!-- end Personel_0 -->

  <!-- Personel_0: PersonelElts Person -->
  <xsl:template name="Person_0">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test="self::per:Person">

        <!-- expect only attributes: per:ID -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::per:ID"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected Person_0 attribute'"/>
                <xsl:with-param name="expected" select="'&lt;per:Person&gt; @per:ID=@xsd:NMTOKEN'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected Person_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:Person&gt; @per:ID=@xsd:NMTOKEN'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="Person_1">
      <xsl:with-param name="__PATH" select="$__PATH"/>
      <xsl:with-param name="subject" select="concat('&lt;', $baseURI, '#', @per:ID, '&gt;')"/>
    </xsl:call-template>
  </xsl:template><!-- end Person_0 -->

  <!-- chained template to assign subject -->
  <xsl:template name="Person_1">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>

    <!-- call productions for nested elements -->
    <xsl:for-each select="*">
      <xsl:choose>
        <xsl:when test="self::per:given">
          <xsl:call-template name="per_given_0">
            <xsl:with-param name="__PATH" select="''"/>
            <xsl:with-param name="subject" select="$subject"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="self::per:family">
          <xsl:call-template name="per_family_0">
            <xsl:with-param name="__PATH" select="''"/>
            <xsl:with-param name="subject" select="$subject"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="self::per:email">
          <xsl:call-template name="per_email_0">
            <xsl:with-param name="__PATH" select="''"/>
            <xsl:with-param name="subject" select="$subject"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="self::per:addr">
          <xsl:call-template name="per_addr_0">
            <xsl:with-param name="__PATH" select="''"/>
            <xsl:with-param name="subject" select="$subject"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="error">
            <xsl:with-param name="hint" select="'no matching Person_1 production'"/>
            <xsl:with-param name="expected" select="'&lt;per:Person&gt; @per:ID=@xsd:NMTOKEN'"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>

  </xsl:template><!-- end Person_1 -->

  <!-- Person_1:  -->
  <xsl:template name="per_given_0">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test="self::per:given">

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected per_given_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:given&gt; '"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="addTriple_lit">
      <xsl:with-param name="predicate" select="$Given"/>
      <xsl:with-param name="subject" select="$subject"/>
      <xsl:with-param name="object" select="text()"/>
    </xsl:call-template>

    <!-- expect no nested elements -->
    <xsl:for-each select="*">
      <xsl:call-template name="error">
        <xsl:with-param name="hint" select="'unexpected per_given_0'"/>
        <xsl:with-param name="expected" select="'no elements'"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template><!-- end per_given_0 -->

  <!-- Person_1:  -->
  <xsl:template name="per_family_0">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test="self::per:family">

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected per_family_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:family&gt; '"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="addTriple_lit">
      <xsl:with-param name="predicate" select="$Family"/>
      <xsl:with-param name="subject" select="$subject"/>
      <xsl:with-param name="object" select="text()"/>
    </xsl:call-template>

    <!-- expect no nested elements -->
    <xsl:for-each select="*">
      <xsl:call-template name="error">
        <xsl:with-param name="hint" select="'unexpected per_family_0'"/>
        <xsl:with-param name="expected" select="'no elements'"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template><!-- end per_family_0 -->

  <!-- Person_1:  -->
  <xsl:template name="per_email_0">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test="self::per:email">

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected per_email_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:email&gt; '"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="addTriple">
      <xsl:with-param name="predicate" select="$Email"/>
      <xsl:with-param name="subject" select="$subject"/>
      <xsl:with-param name="object" select="concat('&lt;mailto:', text(), '&gt;')"/>
    </xsl:call-template>

    <!-- expect no nested elements -->
    <xsl:for-each select="*">
      <xsl:call-template name="error">
        <xsl:with-param name="hint" select="'unexpected per_email_0'"/>
        <xsl:with-param name="expected" select="'no elements'"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template><!-- end per_email_0 -->

  <!-- Person_1:  -->
  <xsl:template name="per_addr_0">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test="self::per:addr">

        <!-- expect only attributes: per:href -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::per:href"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected per_addr_0 attribute'"/>
                <xsl:with-param name="expected" select="'&lt;per:addr&gt; @per:href'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected per_addr_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:addr&gt; @per:href'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="addTriple_ref">
      <xsl:with-param name="predicate" select="$Addr"/>
      <xsl:with-param name="subject" select="$subject"/>
      <xsl:with-param name="object" select="@per:href"/>
      <xsl:with-param name="baseUri" select="$baseURI"/>
    </xsl:call-template>

    <!-- expect no nested elements -->
    <xsl:for-each select="*">
      <xsl:call-template name="error">
        <xsl:with-param name="hint" select="'unexpected per_addr_0'"/>
        <xsl:with-param name="expected" select="'no elements'"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template><!-- end per_addr_0 -->

  <!-- Personel_0: PersonelElts Department -->
  <xsl:template name="Department_0">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test="self::per:Departement">

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected Department_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:Departement&gt; '"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="Department_1">
      <xsl:with-param name="__PATH" select="$__PATH"/>
      <xsl:with-param name="subject" select="concat('&lt;', $baseURI, '#', per:name, '&gt;')"/>
    </xsl:call-template>
  </xsl:template><!-- end Department_0 -->

  <!-- chained template to assign subject -->
  <xsl:template name="Department_1">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>

    <!-- call productions for nested elements -->
    <xsl:for-each select="*">
      <xsl:choose>
        <xsl:when test="self::per:name">
          <xsl:call-template name="per_name_0">
            <xsl:with-param name="__PATH" select="''"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="self::per:manager">
          <xsl:call-template name="per_manager_0">
            <xsl:with-param name="__PATH" select="''"/>
            <xsl:with-param name="subject" select="$subject"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="self::per:grunt">
          <xsl:call-template name="per_grunt_0">
            <xsl:with-param name="__PATH" select="''"/>
            <xsl:with-param name="subject" select="$subject"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="self::per:location">
          <xsl:call-template name="per_location_0">
            <xsl:with-param name="__PATH" select="''"/>
            <xsl:with-param name="subject" select="$subject"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="error">
            <xsl:with-param name="hint" select="'no matching Department_1 production'"/>
            <xsl:with-param name="expected" select="'&lt;per:Departement&gt; '"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>

  </xsl:template><!-- end Department_1 -->

  <!-- Department_1:  -->
  <xsl:template name="per_name_0">
    <xsl:param name="__PATH"/>
    <xsl:choose>
      <xsl:when test="self::per:name">

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected per_name_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:name&gt; '"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>


    <!-- expect no nested elements -->
    <xsl:for-each select="*">
      <xsl:call-template name="error">
        <xsl:with-param name="hint" select="'unexpected per_name_0'"/>
        <xsl:with-param name="expected" select="'no elements'"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template><!-- end per_name_0 -->

  <!-- Department_1:  -->
  <xsl:template name="per_manager_0">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test="self::per:manager">

        <!-- expect only attributes: per:href -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::per:href"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected per_manager_0 attribute'"/>
                <xsl:with-param name="expected" select="'&lt;per:manager&gt; @per:href'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected per_manager_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:manager&gt; @per:href'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="addTriple_ref">
      <xsl:with-param name="predicate" select="$Manager"/>
      <xsl:with-param name="subject" select="$subject"/>
      <xsl:with-param name="object" select="@per:href"/>
      <xsl:with-param name="baseUri" select="$baseURI"/>
    </xsl:call-template>

    <!-- expect no nested elements -->
    <xsl:for-each select="*">
      <xsl:call-template name="error">
        <xsl:with-param name="hint" select="'unexpected per_manager_0'"/>
        <xsl:with-param name="expected" select="'no elements'"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template><!-- end per_manager_0 -->

  <!-- Department_1:  -->
  <xsl:template name="per_grunt_0">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test="self::per:grunt">

        <!-- expect only attributes: per:href -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::per:href"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected per_grunt_0 attribute'"/>
                <xsl:with-param name="expected" select="'&lt;per:grunt&gt; @per:href'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected per_grunt_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:grunt&gt; @per:href'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="addTriple_ref">
      <xsl:with-param name="predicate" select="$Grunt"/>
      <xsl:with-param name="subject" select="$subject"/>
      <xsl:with-param name="object" select="@per:href"/>
      <xsl:with-param name="baseUri" select="$baseURI"/>
    </xsl:call-template>

    <!-- expect no nested elements -->
    <xsl:for-each select="*">
      <xsl:call-template name="error">
        <xsl:with-param name="hint" select="'unexpected per_grunt_0'"/>
        <xsl:with-param name="expected" select="'no elements'"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template><!-- end per_grunt_0 -->

  <!-- Department_1:  -->
  <xsl:template name="per_location_0">
    <xsl:param name="__PATH"/>
    <xsl:param name="subject"/>
    <xsl:choose>
      <xsl:when test="self::per:location">

        <!-- expect only attributes: per:href -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::per:href"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected per_location_0 attribute'"/>
                <xsl:with-param name="expected" select="'&lt;per:location&gt; @per:href'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected per_location_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;per:location&gt; @per:href'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="addTriple_ref">
      <xsl:with-param name="predicate" select="$Location"/>
      <xsl:with-param name="subject" select="$subject"/>
      <xsl:with-param name="object" select="@per:href"/>
      <xsl:with-param name="baseUri" select="$baseURI"/>
    </xsl:call-template>

    <!-- expect no nested elements -->
    <xsl:for-each select="*">
      <xsl:call-template name="error">
        <xsl:with-param name="hint" select="'unexpected per_location_0'"/>
        <xsl:with-param name="expected" select="'no elements'"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template><!-- end per_location_0 -->

  <!-- Personel_0: PersonelElts Address -->
  <xsl:template name="Address_0">
    <xsl:param name="__PATH"/>
    <xsl:choose>
      <xsl:when test="self::addr:Address">

        <!-- expect only attributes: per:ID -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::per:ID"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected Address_0 attribute'"/>
                <xsl:with-param name="expected" select="'&lt;addr:Address&gt; @per:ID=@xsd:NMTOKEN'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected Address_0 element'"/>
          <xsl:with-param name="expected" select="'&lt;addr:Address&gt; @per:ID=@xsd:NMTOKEN'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <!-- call actions for annotations on calling productions -->
    <xsl:choose>
      <xsl:when test="$__PATH = 'PersonelElts Address'">
        <xsl:call-template name="addTriple_lit">
          <xsl:with-param name="predicate" select="$StreetAddr"/>
          <xsl:with-param name="subject" select="concat('&lt;', $baseURI, '#', @per:ID, '&gt;')"/>
          <xsl:with-param name="object" select="text()"/>
        </xsl:call-template>
      </xsl:when>
    </xsl:choose>

    <!-- expect no nested elements -->
    <xsl:for-each select="*">
      <xsl:call-template name="error">
        <xsl:with-param name="hint" select="'unexpected Address_0'"/>
        <xsl:with-param name="expected" select="'no elements'"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template><!-- end Address_0 -->

</xsl:transform>
