Nearly Round-Tripping

Well, it's nearly there. The PHP implementation now supports the generation of elements given only the URI (as opposed to supplying the namespace and local parts separately) which was the major blocker on getting this working. I've extended the spec to allow NodePaths to be specified in the rt:name attribute of rt:element. They're distinguished from string values by enclosing them in curly brackets {} just like in XSLT. I'll do the same for attributes too. There's still some work to do on the actual XML generation around the namespace prefixes but it's essentially all there. The stylesheet itself would be cleaner with some conditional logic in there - that will come soon too.

Here's the stylesheet:

<rt:stylesheet xmlns:rt="http://purl.org/vocab/2003/rdft/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  >
  <rt:output rt:method="xml" rt:indent="yes"/>

  <rt:root-template>
    <rdf:RDF>
      <rt:for-each rt:select="~subject()">
        <rdf:Description>
          <rt:attribute rt:name="about" rt:namespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
            <rt:value-of rt:select="label()" />
          </rt:attribute>

          <rt:for-each rt:select="node()/resource()">
            <rt:element rt:name="{label()}">
              <rt:for-each rt:select="resource()/resource()">
                <rt:attribute rt:name="resource" rt:namespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
                  <rt:value-of rt:select="label()" />
                </rt:attribute>
              </rt:for-each>
              <rt:for-each rt:select="resource()/literal()">
                  <rt:value-of rt:select="label()" />
              </rt:for-each>
            </rt:element>
          </rt:for-each>
          
        </rdf:Description>
      </rt:for-each>
    </rdf:RDF>
  </rt:root-template>
</rt:stylesheet>
(more…)

Namespace Handling

After a bit of a breather, I'm back working on RDF Templates. My current focus is getting namespace handling to work correctly. This is a very small spec change but quite a lot of work in the PHP implementation. I have rudimentary handling sorted out now, but I'm ignoring some of the finer points such as unprefixed namespaces. These will come along shortly.

Along the way I've added an rt:output element which is the RDFT analog of xsl:output. It lets you specify options such as XML or text output. I'm gradually edging towards the RDF syntax round-tripping milestone.

After namespace handling is polished off I need to look at using RDFT elements to generate the values of attributes. This should be fairly simple because the current attribute implementation uses an rt:text action for the value anyway, it's just an extension of that to make it more explicit.