Re: [xsl] RDF/OWL Transformation using XSL - Backtracking Parent Classes ?

Subject: Re: [xsl] RDF/OWL Transformation using XSL - Backtracking Parent Classes ?
From: "James A. Robinson" <jim.robinson@xxxxxxxxxxxx>
Date: Sat, 25 Nov 2006 18:29:56 -0800
> However as you can see the relationship is part of each element, as
> opposed to having the element nested within each other based on their
> relationship.
> 
> If the relationships were going downwards it would be easy, i.e. The
> "Grandad" class would state what classes are inheriting from it,
> however as inheritance and classes don't work this way, i don't know
> how these relationships can be converted to a hierarchy structure such

I'd usually think of this is a problem in recursion. Given a starting
point, Grandad, how can you identify direct descendents of Grandad,
resolving to Dad?  Given Dad, how can you resolve direct descendents of
Dad, Son and Daughter?

There are probably details I'm totally unaware of w/re to the RDF/OWL
schemas, but just eyeballing it it looks to me like the following XPath
finds direct descendents of a given owl:Class:

        //owl:Class[
          rdfs:subClassOf[
            @rdf:resource=current()/@rdf:about 
            or owl:Class/@rdf:about=current()/@rdf:about]]"

Assuming my guess is at least feasible, you can then wrap
it in a template match:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0"
  xmlns:rdf=" http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#";
  xmlns:owl="http://www.w3.org/2002/07/owl#";
  xmlns:xs="http://www.w3.org/2001/XMLSchema";
  xmlns:local="uri.local-functions">
  
  <xsl:output indent="yes"/>

  <xsl:template match="/">
    <xsl:apply-templates select="/rdf:RDF/owl:Class[@rdf:about='#Grandad']" />
  </xsl:template>

  <xsl:template match="owl:Class">
    <xsl:variable name="name" select="local:name-of(.)"/>
    <xsl:element name="{$name}">
      <xsl:apply-templates
        select="
        //owl:Class[
          rdfs:subClassOf[
            @rdf:resource=current()/@rdf:about 
            or owl:Class/@rdf:about=current()/@rdf:about]]"
      />
    </xsl:element>
  </xsl:template>

  <xsl:function name="local:name-of" as="xs:string">
    <xsl:param name="class" as="element(owl:Class)"/>
    <xsl:choose>
      <xsl:when test="$class/@rdf:ID">
        <xsl:value-of select="$class/@rdf:ID"/>
      </xsl:when>
      <xsl:when test="$class/@rdf:about">
        <xsl:value-of select="substring($class/@rdf:about, 2)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message terminate="yes">
          <xsl:text>Unable to extrapolate an element name from </xsl:text>
          <xsl:sequence select="$class"/>
        </xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>

</xsl:stylesheet>

which will emit:

<?xml version="1.0" encoding="UTF-8"?>
<Grandad>
   <Dad>
      <Son/>
      <Daughter/>
   </Dad>
</Grandad>

or, if you change the match for / to apply templates to #Dad:

<Dad>
   <Son/>
   <Daughter/>
</Dad>

Jim

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       jim.robinson@xxxxxxxxxxxx
Stanford University HighWire Press      http://highwire.stanford.edu/
+1 650 7237294 (Work)                   +1 650 7259335 (Fax)

Current Thread