<!-- RDFXMLtoRdfXS.xsl - XSLT to transform RDF to database API calls.
- based on http://www.w3.org/2002/03/11-RDF-XSL/rdfToDB.xsl
description and revision history at http://www.w3.org/2002/03/11-RDF-XSL/
$Id: rngSerializer,v 1.5 2003/12/28 10:34:27 eric Exp 0->

<xsl:transform version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

  <!-- 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"/>

<!-- xsl:value-of select="concat('/ at:', local-name(.), '&#xA;')"/ -->


  <!-- start with root node -->
  <xsl:template match="/">
    <!-- rely on XSLT processor to make sure there is only one root (RDF_0) -->
    <xsl:for-each select="*">
      <xsl:call-template name="RDF_0"/>
    </xsl:for-each>
  </xsl:template>


  <xsl:template name="RDF_0">
    <xsl:choose>

      <!-- start: doc RDF -->
      <xsl:when test="self::rdf:RDF">

        <!-- expect only attributes: @@xml:lang, @@xml:base -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::@xml:lang"/>
            <xsl:when test="self::@xml:base"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected attribute'"/>
                <xsl:with-param name="expected" select="'rdf:RDF @@xml:lang, @@xml:base'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

        <xsl:for-each select="*">
          <xsl:call-template name="emptyPropertyElt_0"/>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected element'"/>
          <xsl:with-param name="expected" select="'rdf:RDF @@xml:lang, @@xml:base'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="nodeElement_0">
    <xsl:choose>

      <!-- RDF_0: nodeElementList * nodeElement -->
      <!-- resourcePropertyElt_0: nodeElement -->
      <!-- parseTypeCollectionPropertyElt_0: nodeElementList * nodeElement -->
      <xsl:when test="self::*">

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

        <xsl:for-each select="*">
          <xsl:call-template name="emptyPropertyElt_0"/>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected element'"/>
          <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@rdf:nodeID=@xsd:NMTOKEN, @@rdf:about, @@xml:lang, @@xml:base, @&lt;*&gt;'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="resourcePropertyElt_0">
    <xsl:choose>

      <!-- nodeElement_0: propertyEltList * propertyElt resourcePropertyElt -->
      <!-- parseTypeResourcePropertyElt_0: propertyEltList * propertyElt resourcePropertyElt -->
      <xsl:when test="self::*">

        <!-- expect only attributes: @@rdf:ID=@xsd:NMTOKEN, @@xml:lang, @@xml:base -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::@rdf:ID=@xsd:NMTOKEN"/>
            <xsl:when test="self::@xml:lang"/>
            <xsl:when test="self::@xml:base"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected attribute'"/>
                <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@xml:lang, @@xml:base'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

        <xsl:for-each select="*">
          <xsl:call-template name="???"/>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected element'"/>
          <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@xml:lang, @@xml:base'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="literalPropertyElt_0">
    <xsl:choose>

      <!-- nodeElement_0: propertyEltList * propertyElt literalPropertyElt -->
      <!-- parseTypeResourcePropertyElt_0: propertyEltList * propertyElt literalPropertyElt -->
      <xsl:when test="self::*">

        <!-- expect only attributes: @@rdf:ID=@xsd:NMTOKEN, @@rdf:datatype, @@xml:lang, @@xml:base -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::@rdf:ID=@xsd:NMTOKEN"/>
            <xsl:when test="self::@rdf:datatype"/>
            <xsl:when test="self::@xml:lang"/>
            <xsl:when test="self::@xml:base"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected attribute'"/>
                <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@rdf:datatype, @@xml:lang, @@xml:base'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

        <xsl:for-each select="*">
          <xsl:call-template name="???"/>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected element'"/>
          <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@rdf:datatype, @@xml:lang, @@xml:base'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="parseTypeLiteralPropertyElt_0">
    <xsl:choose>

      <!-- nodeElement_0: propertyEltList * propertyElt parseTypeLiteralPropertyElt -->
      <!-- parseTypeResourcePropertyElt_0: propertyEltList * propertyElt parseTypeLiteralPropertyElt -->
      <xsl:when test="self::*">

        <!-- expect only attributes: @@rdf:ID=@xsd:NMTOKEN, @@rdf:parseType=&quot;Literal&quot;, @@xml:lang, @@xml:base -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::@rdf:ID=@xsd:NMTOKEN"/>
            <xsl:when test="self::@rdf:parseType="Literal""/>
            <xsl:when test="self::@xml:lang"/>
            <xsl:when test="self::@xml:base"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected attribute'"/>
                <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@rdf:parseType=&quot;Literal&quot;, @@xml:lang, @@xml:base'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

        <xsl:for-each select="*">
          <xsl:call-template name="???"/>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected element'"/>
          <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@rdf:parseType=&quot;Literal&quot;, @@xml:lang, @@xml:base'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="parseTypeResourcePropertyElt_0">
    <xsl:choose>

      <!-- nodeElement_0: propertyEltList * propertyElt parseTypeResourcePropertyElt -->
      <!-- parseTypeResourcePropertyElt_0: propertyEltList * propertyElt parseTypeResourcePropertyElt -->
      <xsl:when test="self::*">

        <!-- expect only attributes: @@rdf:ID=@xsd:NMTOKEN, @@rdf:parseType=&quot;Resource&quot;, @@xml:lang, @@xml:base -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::@rdf:ID=@xsd:NMTOKEN"/>
            <xsl:when test="self::@rdf:parseType="Resource""/>
            <xsl:when test="self::@xml:lang"/>
            <xsl:when test="self::@xml:base"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected attribute'"/>
                <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@rdf:parseType=&quot;Resource&quot;, @@xml:lang, @@xml:base'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

        <xsl:for-each select="*">
          <xsl:call-template name=""/>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected element'"/>
          <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@rdf:parseType=&quot;Resource&quot;, @@xml:lang, @@xml:base'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="parseTypeCollectionPropertyElt_0">
    <xsl:choose>

      <!-- parseTypeResourcePropertyElt_0: propertyEltList * propertyElt parseTypeCollectionPropertyElt -->
      <!-- nodeElement_0: propertyEltList * propertyElt parseTypeCollectionPropertyElt -->
      <xsl:when test="self::*">

        <!-- expect only attributes: @@rdf:ID=@xsd:NMTOKEN, @@xml:lang, @@xml:base, @@rdf:parseType=&quot;Collection&quot; -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::@rdf:ID=@xsd:NMTOKEN"/>
            <xsl:when test="self::@xml:lang"/>
            <xsl:when test="self::@xml:base"/>
            <xsl:when test="self::@rdf:parseType="Collection""/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected attribute'"/>
                <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@xml:lang, @@xml:base, @@rdf:parseType=&quot;Collection&quot;'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

        <xsl:for-each select="*">
          <xsl:call-template name="???"/>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected element'"/>
          <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@xml:lang, @@xml:base, @@rdf:parseType=&quot;Collection&quot;'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="parseTypeOtherPropertyElt_0">
    <xsl:choose>

      <!-- parseTypeResourcePropertyElt_0: propertyEltList * propertyElt parseTypeOtherPropertyElt -->
      <!-- nodeElement_0: propertyEltList * propertyElt parseTypeOtherPropertyElt -->
      <xsl:when test="self::*">

        <!-- expect only attributes: @@rdf:ID=@xsd:NMTOKEN, @@xml:lang, @@xml:base, @@rdf:parseType -->
        <xsl:for-each select="./@*">
          <xsl:choose>
            <xsl:when test="self::@rdf:ID=@xsd:NMTOKEN"/>
            <xsl:when test="self::@xml:lang"/>
            <xsl:when test="self::@xml:base"/>
            <xsl:when test="self::@rdf:parseType"/>
            <xsl:otherwise>
              <xsl:call-template name="error">
                <xsl:with-param name="hint" select="'unexpected attribute'"/>
                <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@xml:lang, @@xml:base, @@rdf:parseType'"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>

        <xsl:for-each select="*">
          <xsl:call-template name="???"/>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected element'"/>
          <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@xml:lang, @@xml:base, @@rdf:parseType'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="emptyPropertyElt_0">
    <xsl:choose>

      <!-- parseTypeResourcePropertyElt_0: propertyEltList * propertyElt emptyPropertyElt -->
      <!-- nodeElement_0: propertyEltList * propertyElt emptyPropertyElt -->
      <xsl:when test="self::*">

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

        <xsl:for-each select="*">
          <xsl:call-template name="???"/>
        </xsl:for-each>

      </xsl:when>

      <!-- didn't match any productions -->
      <xsl:otherwise>
        <xsl:call-template name="error">
          <xsl:with-param name="hint" select="'unexpected element'"/>
          <xsl:with-param name="expected" select="'* @@rdf:ID=@xsd:NMTOKEN, @@rdf:resource, @@rdf:nodeID=@xsd:NMTOKEN, @@xml:lang, @@xml:base, @&lt;*&gt;'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:transform>
