<!-- -*- mode: indented-text;-*- -->
<xsl:transform
    xmlns:xsl  ="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:xi   ="http://www.w3.org/2000/07/infoset#"
    xmlns:rdf  ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:x2r  ="http://www.w3.org/2000/07/hs78/content.xsl?template="
    xmlns:xia  ="http://www.w3.org/2000/07/hs78/content.xsl?term="
	>
<div xmlns="http://www.w3.org/1999/xhtml">

<p><cite><a
href="http://www.w3.org/TR/2000/WD-xml-infoset-20000726">XML
Information Set</a></cite><br /> W3C Working Draft 26 July 2000</p>

<h2>Share and Enjoy</h2>

<p>Copyright (c) 2000 W3C (MIT, INRIA, Keio), released under the <a
href="http://www.w3.org/Consortium/Legal/copyright-software-19980720">
W3C Open Source License</a> of August 14 1998.  </p>

<address><a href="../../../People/Connolly/">Dan Connolly</a>, Aug 2000<br />
$Revision: 1.3 $ of $Date: 2001/10/10 19:28:58 $ by $Author: connolly $
</address>
</div>

<xsl:variable name="xiNS"
	      select='"http://www.w3.org/2000/07/infoset#"'/>

<xsl:variable name="rdfNS"
	      select='"http://www.w3.org/1999/02/22-rdf-syntax-ns#"'/>

<xsl:template name="x2r:element"
	      mode="x2r:content" match="*">
  <!-- http://www.w3.org/TR/2000/WD-xml-infoset-20000726#infoitem.element -->
  <xsl:variable name="nsn" select='namespace-uri()'/> <!-- @@ xml-uri -->
  <xsl:variable name="ln" select='local-name()'/>
  <xsl:variable name="id" select='generate-id()'/>

  <rdf:li> <!-- @@ omit at top level somehow? -->
    <xi:Element
        ID="{$id}"
	xi:namespaceName="{$nsn}"
	xi:localName="{$ln}"
	>
      <xi:attributes>
        <rdf:Bag>
	  <!-- @@put an ID on this, give it rdf:type InfoItemSet,
	       @@record the number of items in it. -->
          <xsl:for-each select='@*'>
            <xsl:call-template name="x2r:attribute">
              <xsl:with-param name="ownerId" select='$id'/>
            </xsl:call-template>
          </xsl:for-each>
	</rdf:Bag>
      </xi:attributes>

      <xi:children>
        <rdf:Seq>
          <xsl:apply-templates mode="x2r:content"/>
	  <xia:length rdf:resource='{concat($rdfNS,
					    "_",
					    string(count(*)+count(text())))}'/>
	  <!-- @@record the number of items in the sequence; somehow,
	       positively record that there are no other items
	       in this sequence -->
        </rdf:Seq>
      </xi:children>
    </xi:Element>
  </rdf:li>
</xsl:template>

<xsl:template name="x2r:attribute">
  <xsl:param name="ownerId"/>

  <xsl:variable name="nsn" select='namespace-uri()'/> <!-- @@ xml-uri -->
  <xsl:variable name="ln" select='local-name()'/>

  <rdf:li>
    <xi:Attribute
	xi:localName="{$ln}"
	xi:normalizedValue="{string(.)}"
	>
      <xsl:if test='$nsn'>
        <xsl:attribute name="namespaceName" namespace="{$xiNS}">
	  <xsl:value-of select="$nsn"/>
	</xsl:attribute>
      </xsl:if> <!-- @@else...? how to indicate a null namespace name? -->

      <xi:ownerElement resource='{concat("#", $ownerId)}'/>
    </xi:Attribute>
  </rdf:li>

  <!-- XPath model doesn't see children, specified, default,
       attribute type (@@check) -->

</xsl:template>

<xsl:template name="x2r:text"
	      mode="x2r:content" match="text()">
  <rdf:li>
    <xia:Characters rdf:value="{string(.)}"/> <!-- @@ text/char mismatch -->
  </rdf:li>
</xsl:template>

<xsl:template name="x2r:other"
	      mode="x2r:content" match="processing-instruction()">
  <xsl:message>@@pi not implemented</xsl:message>
</xsl:template>

<xsl:template name="x2r:comment"
	      mode="x2r:content" match="processing-instruction()">
  <xsl:message>@@comment not implemented</xsl:message>
</xsl:template>

<!-- test harness -->
<xsl:template match="*">
  <xsl:call-template name="x2r:element"/>
</xsl:template>

</xsl:transform>
