XSL Transformation of .owl file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fredrik Henricsson

    XSL Transformation of .owl file

    Hey, I'm building an ontology in Protégé and I want to transform parts of it
    (e.g. the instances) to HTML with XSL. When I was transforming another file
    with 'simple' XML-tags like <author> before, I got it working, but the
    OWL-file is formatted differently and I don't know how to access the
    elements. I'll post the .owl file below, but this is basically what I want
    to get from the file (the course name):

    <Course rdf:ID="Advance dKnowledgeTechn ology">
    <CourseName rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
    >Advanced Knowledge Technology</CourseName>[/color]
    ....
    </Course>

    Any kind of help is appreciated.

    The OWL-file:

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="MasterAI. xsl"?>
    <rdf:RDF
    xmlns:rdf="http ://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="htt p://www.w3.org/2000/01/rdf-schema#"
    xmlns:owl="http ://www.w3.org/2002/07/owl#"
    xmlns="http://www.owl-ontologies.com/unnamed.owl#"
    xml:base="http://www.owl-ontologies.com/unnamed.owl">
    <owl:Ontology rdf:about=""/>
    <owl:Class rdf:ID="Program me">
    <rdfs:subClassO f>
    <owl:Class rdf:ID="MasterA I"/>
    </rdfs:subClassOf >
    <owl:disjointWi th>
    <owl:Class rdf:ID="Univers ity"/>
    </owl:disjointWit h>
    <owl:disjointWi th>
    <owl:Class rdf:ID="Course"/>
    </owl:disjointWit h>
    <owl:equivalent Class>
    <owl:Class>
    <owl:intersecti onOf rdf:parseType=" Collection">
    <owl:Restrictio n>
    <owl:allValuesF rom>
    <owl:Class rdf:about="#Cou rse"/>
    </owl:allValuesFr om>
    <owl:onProperty >
    <owl:ObjectProp erty rdf:ID="hasCour se"/>
    </owl:onProperty>
    </owl:Restriction >
    <owl:Restrictio n>
    <owl:onProperty >
    <owl:ObjectProp erty rdf:about="#has Course"/>
    </owl:onProperty>
    <owl:someValues From>
    <owl:Class rdf:about="#Cou rse"/>
    </owl:someValuesF rom>
    </owl:Restriction >
    </owl:intersectio nOf>
    </owl:Class>
    </owl:equivalentC lass>
    </owl:Class>
    <owl:Class rdf:about="#Cou rse">
    <owl:disjointWi th>
    <owl:Class rdf:about="#Uni versity"/>
    </owl:disjointWit h>
    <rdfs:subClassO f rdf:resource="# MasterAI"/>
    <owl:disjointWi th rdf:resource="# Programme"/>
    </owl:Class>
    <owl:Class rdf:about="#Uni versity">
    <rdfs:subClassO f rdf:resource="# MasterAI"/>
    <owl:disjointWi th rdf:resource="# Course"/>
    <owl:equivalent Class>
    <owl:Class>
    <owl:intersecti onOf rdf:parseType=" Collection">
    <owl:Restrictio n>
    <owl:onProperty >
    <owl:ObjectProp erty rdf:ID="hasProg ramme"/>
    </owl:onProperty>
    <owl:allValuesF rom rdf:resource="# Programme"/>
    </owl:Restriction >
    <owl:Restrictio n>
    <owl:someValues From rdf:resource="# Programme"/>
    <owl:onProperty >
    <owl:ObjectProp erty rdf:about="#has Programme"/>
    </owl:onProperty>
    </owl:Restriction >
    </owl:intersectio nOf>
    </owl:Class>
    </owl:equivalentC lass>
    <owl:disjointWi th rdf:resource="# Programme"/>
    </owl:Class>
    <owl:Class rdf:ID="Program meAI">
    <rdfs:subClassO f rdf:resource="# Programme"/>
    </owl:Class>
    <owl:ObjectProp erty rdf:about="#has Programme">
    <rdfs:domain rdf:resource="# University"/>
    <rdf:type
    rdf:resource="h ttp://www.w3.org/2002/07/owl#InverseFunc tionalProperty"/>
    <rdfs:range rdf:resource="# Programme"/>
    <owl:inverseO f>
    <owl:Functional Property rdf:ID="isProgr ammeOf"/>
    </owl:inverseOf>
    </owl:ObjectPrope rty>
    <owl:ObjectProp erty rdf:about="#has Course">
    <rdfs:range rdf:resource="# Course"/>
    <rdfs:domain rdf:resource="# Programme"/>
    <owl:inverseO f>
    <owl:ObjectProp erty rdf:ID="isCours eOf"/>
    </owl:inverseOf>
    </owl:ObjectPrope rty>
    <owl:ObjectProp erty rdf:about="#isC ourseOf">
    <rdfs:domain rdf:resource="# Course"/>
    <owl:inverseO f rdf:resource="# hasCourse"/>
    <rdfs:range rdf:resource="# Programme"/>
    </owl:ObjectPrope rty>
    <owl:DatatypePr operty rdf:ID="CourseN ame">
    <rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
    <rdfs:domain rdf:resource="# Course"/>
    <rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#FunctionalP roperty"/>
    </owl:DatatypePro perty>
    <owl:DatatypePr operty rdf:ID="CourseE CTS">
    <rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#FunctionalP roperty"/>
    <rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#float "/>
    <rdfs:domain rdf:resource="# Course"/>
    </owl:DatatypePro perty>
    <owl:Functional Property rdf:ID="Program meName">
    <rdfs:domain rdf:resource="# Programme"/>
    <rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#DatatypePro perty"/>
    <rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
    </owl:FunctionalP roperty>
    <owl:Functional Property rdf:ID="Univers ityName">
    <rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#DatatypePro perty"/>
    <rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
    <rdfs:domain rdf:resource="# University"/>
    </owl:FunctionalP roperty>
    <owl:Functional Property rdf:about="#isP rogrammeOf">
    <owl:inverseO f rdf:resource="# hasProgramme"/>
    <rdfs:range rdf:resource="# University"/>
    <rdfs:domain rdf:resource="# Programme"/>
    <rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#ObjectPrope rty"/>
    </owl:FunctionalP roperty>

    <Course rdf:ID="Advance dKnowledgeTechn ology">
    <CourseName rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
    >Advanced Knowledge Technology</CourseName>[/color]
    <isCourseOf>
    <ProgrammeAI rdf:ID="MensMac hineCommunicati e">
    <ProgrammeNam e rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
    >Mens-Machine Communicatie en Artificial Intelligence</ProgrammeName>[/color]
    <hasCourse rdf:resource="# AdvancedKnowled geTechnology"/>
    <isProgrammeO f>
    <University rdf:ID="Groning enRuG">
    <UniversityNa me rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
    >Groningen(RuG) </UniversityName>[/color]
    <hasProgramme rdf:resource="# MensMachineComm unicatie"/>
    </University>
    </isProgrammeOf>
    </ProgrammeAI>
    </isCourseOf>
    <CourseECTS rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#float "[color=blue]
    >5.0</CourseECTS>[/color]
    </Course>

    </rdf:RDF>


  • Andy Dingley

    #2
    Re: XSL Transformation of .owl file

    On Thu, 24 Mar 2005 00:08:55 +0100, "Fredrik Henricsson"
    <faid@swipnet.s e> wrote:
    [color=blue]
    >Hey, I'm building an ontology in Protégé and I want to transform parts of it
    >(e.g. the instances) to HTML with XSL.[/color]

    I can't work out what you're trying to achieve here.

    Are you using the ontology, or are you just extracting the instance
    data you've stored in it ? Your example appears to be a trivial
    example of "Turn some XML into HTML with escaping of the &lt;"
    That's in every beginner's XSLT book


    Try the following fragments for starters:

    <xslt:templat e mode="copying" match="@*" ><xslt:text>
    </xslt:text><xslt :value-of select="name()" />="<xslt:valu e-of
    select="." />"</xslt:template>


    <xslt:templat e mode="copying" match="text()" ><xslt:value-of
    select="." /></xslt:template>


    <xslt:templat e mode="copying" match="*" >
    &lt;<xslt:va lue-of select="local-name()" /><xslt:apply-templates
    mode="copying" select="@*" /><xslt:choose >

    <xslt:when test="*|text()" >&gt;<xslt:appl y-templates
    select="*|text( )" mode="copying" />&lt;/<xslt:value-of
    select="local-name()" /></xslt:when>

    <xslt:otherwise >/</xslt:otherwise>
    </xslt:choose>&gt ;</xslt:template>


    <xslt:templat e name="extract-coursename" >
    <xslt:param name="course" select="//ont:Course[1]" />

    &lt;<xslt:va lue-of select="local-name()" /><xslt:apply-templates
    mode="copying" select="@*" />&gt;<xslt:fo r-each select="*" >
    <xslt:apply-templates select="." mode="copying" />
    </xslt:for-each>&lt;/<xslt:value-of select="local-name()" />&gt;

    </xslt:template>




    If you're trying to use the ontology itself, then you'll have to give
    us an example of what you're looking for as output.

    That's not an OWL problem anyway, so much as an RDF / XSLT problem.
    RDF is _not_ an appropriate candidate for XSLT ! It's really painful
    to do this. You're better with Jena, or an ontology toolkit.

    You _can_ do it, providing that the RDF you're working with is a
    fairly small subset of the possible valid RDF syntaxes for how it can
    be represented in XML. RDF operates at the level of the triples in
    its data model, XML barely has a data model and so XSLT/XPath operates
    on the raw syntax. If you try and express every valid possibility in
    XSLT, you'll go mad.

    I'm afraid I don't have time to post a big example, but if you're
    looking for an example of how to track RDF through rdf:about, then try
    this

    Some data:

    <rdf:li rdf:about="#mat erial_beads">
    <dc:title>Beads </dc:title>
    <dc:description >Glass beads</dc:description>
    </rdf:li>


    <rdf:li rdf:about="#123 ">
    <dc:subject dcq:subjectType ="#materials"># material_beads</dc:subject>
    <dc:subject dcq:subjectType ="#materials"># material_glass</dc:subject>
    </rdf:li>


    Some XSLT:

    <xslt:variabl e name="item"
    select="//rdf:li[(substring-after(@rdf:abou t,'#')=string ('123'))]" />


    <!-- Set of "materisl" referenced -->
    <xslt:variabl e name="materials "
    select="//rdf:Description[(substring-after(@rdf:type ,'#')='material s')]/rdf:li"
    />

    <!-- Set of materials used in this item -->
    <xslt:variabl e name="item-materials"
    select="$item/dc:subject[substring-after(@dcq:subj ectType,'#')='m aterials']"
    />


    <!--Find description of materials for each material used in item-->
    <xslt:for-each select="$item-materials" >
    <xslt:variabl e name="material-description"
    select="$materi als[@rdf:about = current()]" />

    <!-- Do something with it -->
    </xslt:for-each>



    Comment

    • Fredrik Henricsson

      #3
      Re: XSL Transformation of .owl file

      > I can't work out what you're trying to achieve here.[color=blue]
      >
      > Are you using the ontology, or are you just extracting the instance
      > data you've stored in it ? Your example appears to be a trivial
      > example of "Turn some XML into HTML with escaping of the &lt;"
      > That's in every beginner's XSLT book
      >[/color]

      Thanks for the extensive response, I've just recently started with XML and
      XSLT so it's much appreciated.
      I should have been more precise in my question; what I really want to do at
      the end is present the instance data
      in different ways. To clarify, in my application Universities have
      Programmes which in turn have Courses. I want to
      show, in HTML, which courses can be found in which universities and in which
      programmes, OR show the data from
      another perspective, for example which courses are worth 5 ECTS. Since I'm
      new to XSLT I do not know which is the best way to approach this, so I tried
      traversing the tree like in the following pseudo code:

      for each Course
      print CourseName
      find out which Programme Course belongs to
      print ProgrammeName
      find out which University Programme belongs to
      print UniversityName

      The problem I encountered was that when I found the Course, I could not
      traverse down to find the ProgrammeName. I don't
      have any books on XSLT unfortunately, so my main source is the web. Any tips
      on approach or direction would be greatly appreciated.
      I've included the .owl file below; the lower part of the file shows the
      instance relations and data.

      <?xml version="1.0"?>
      <?xml-stylesheet type="text/xsl" href="MasterAI. xsl"?>

      <rdf:RDF
      xmlns="file:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#"
      xmlns:protege=" http://protege.stanfor d.edu/plugins/owl/protege#"
      xmlns:rdf="http ://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:rdfs="htt p://www.w3.org/2000/01/rdf-schema#"
      xmlns:owl="http ://www.w3.org/2002/07/owl#"
      xmlns:myns="htt p://www.owl-ontologies.com/unnamed.owl#"
      xml:base="file:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl">
      <owl:Ontology
      rdf:about="file :/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl"/>
      <owl:Ontology rdf:about="http ://www.owl-ontologies.com/unnamed.owl"/>
      <owl:Class rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Pro gramme">
      <rdfs:subClassO f>
      <owl:Class rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Mas terAI"/>
      </rdfs:subClassOf >
      <owl:equivalent Class>
      <owl:Class>
      <owl:intersecti onOf rdf:parseType=" Collection">
      <owl:Restrictio n>
      <owl:onProperty >
      <owl:ObjectProp erty
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#has Course"/>
      </owl:onProperty>
      <owl:allValuesF rom>
      <owl:Class rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Cou rse"/>
      </owl:allValuesFr om>
      </owl:Restriction >
      <owl:Restrictio n>
      <owl:someValues From>
      <owl:Class rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Cou rse"/>
      </owl:someValuesF rom>
      <owl:onProperty >
      <owl:ObjectProp erty
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#has Course"/>
      </owl:onProperty>
      </owl:Restriction >
      </owl:intersectio nOf>
      </owl:Class>
      </owl:equivalentC lass>
      <owl:disjointWi th>
      <owl:Class
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Uni versity"/>
      </owl:disjointWit h>
      <owl:disjointWi th>
      <owl:Class rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Cou rse"/>
      </owl:disjointWit h>
      </owl:Class>
      <owl:Class rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Cou rse">
      <owl:disjointWi th>
      <owl:Class
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Uni versity"/>
      </owl:disjointWit h>
      <rdfs:subClassO f
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Mas terAI"/>
      <owl:disjointWi th
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Pro gramme"/>
      </owl:Class>
      <owl:Class rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Uni versity">
      <owl:equivalent Class>
      <owl:Class>
      <owl:intersecti onOf rdf:parseType=" Collection">
      <owl:Restrictio n>
      <owl:allValuesF rom
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Pro gramme"/>
      <owl:onProperty >
      <owl:ObjectProp erty
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#has Programme"/>
      </owl:onProperty>
      </owl:Restriction >
      <owl:Restrictio n>
      <owl:someValues From
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Pro gramme"/>
      <owl:onProperty >
      <owl:ObjectProp erty
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#has Programme"/>
      </owl:onProperty>
      </owl:Restriction >
      </owl:intersectio nOf>
      </owl:Class>
      </owl:equivalentC lass>
      <rdfs:subClassO f
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Mas terAI"/>
      <owl:disjointWi th
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Cou rse"/>
      <owl:disjointWi th
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Pro gramme"/>
      </owl:Class>
      <owl:Class
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Pro grammeAI">
      <rdfs:subClassO f
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Pro gramme"/>
      </owl:Class>
      <owl:ObjectProp erty
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#has Programme">
      <rdfs:domain
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Uni versity"/>
      <rdf:type
      rdf:resource="h ttp://www.w3.org/2002/07/owl#InverseFunc tionalProperty"/>
      <rdfs:range
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Pro gramme"/>
      <owl:inverseO f>
      <owl:Functional Property
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#isP rogrammeOf"/>
      </owl:inverseOf>
      </owl:ObjectPrope rty>
      <owl:ObjectProp erty
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#has Course">
      <rdfs:range
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Cou rse"/>
      <rdfs:domain
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Pro gramme"/>
      <owl:inverseO f>
      <owl:ObjectProp erty
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#isC ourseOf"/>
      </owl:inverseOf>
      </owl:ObjectPrope rty>
      <owl:ObjectProp erty
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#isC ourseOf">
      <rdfs:domain
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Cou rse"/>
      <owl:inverseO f
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#has Course"/>
      <rdfs:range
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Pro gramme"/>
      </owl:ObjectPrope rty>
      <owl:DatatypePr operty
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Cou rseName">
      <rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
      <rdfs:domain
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Cou rse"/>
      <rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#FunctionalP roperty"/>
      </owl:DatatypePro perty>
      <owl:DatatypePr operty
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Cou rseECTS">
      <rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#FunctionalP roperty"/>
      <rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#float "/>
      <rdfs:domain
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Cou rse"/>
      </owl:DatatypePro perty>
      <owl:Functional Property
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Pro grammeName">
      <rdfs:domain
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Pro gramme"/>
      <rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#DatatypePro perty"/>
      <rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
      </owl:FunctionalP roperty>
      <owl:Functional Property
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#Uni versityName">
      <rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#DatatypePro perty"/>
      <rdfs:range rdf:resource="h ttp://www.w3.org/2001/XMLSchema#strin g"/>
      <rdfs:domain
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Uni versity"/>
      </owl:FunctionalP roperty>
      <owl:Functional Property
      rdf:about="http ://www.owl-ontologies.com/unnamed.owl#isP rogrammeOf">
      <owl:inverseO f
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#has Programme"/>
      <rdfs:domain
      rdf:resource="h ttp://www.owl-ontologies.com/unnamed.owl#Pro gramme"/>
      <rdf:type rdf:resource="h ttp://www.w3.org/2002/07/owl#ObjectPrope rty"/>
      </owl:FunctionalP roperty>
      <myns:Programme AI rdf:ID="AgentsL anguageSpeech">
      <myns:isProgram meOf>
      <myns:Universit y rdf:ID="Utrecht UU">
      <myns:Universit yName rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
      >Utrecht(UU)</myns:University Name>[/color]
      <myns:hasProgra mme>
      <myns:Programme AI rdf:ID="Cogniti veDynamics">
      <myns:isProgram meOf
      rdf:resource="f ile:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Ut rechtUU"/>
      <myns:Programme Name rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
      >Cognitive Dynamics</myns:ProgrammeN ame>[/color]
      <myns:hasCourse >
      <myns:Course rdf:ID="Dynamic Semantics">
      <myns:isCourseO f
      rdf:resource="f ile:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Co gnitiveDynamics "/>
      <myns:CourseNam e rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
      >Dynamic Semantics</myns:CourseName >[/color]
      <myns:isCourseO f>
      <myns:Programme AI rdf:ID="Foundat ionAI">
      <myns:isProgram meOf
      rdf:resource="f ile:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Ut rechtUU"/>
      <myns:Programme Name rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
      >Foundation of AI</myns:ProgrammeN ame>[/color]
      <myns:hasCour se
      rdf:resource="f ile:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Dy namicSemantics"/>
      </myns:ProgrammeA I>
      </myns:isCourseOf >
      <myns:CourseECT S rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#float "[color=blue]
      >7.5</myns:CourseECTS >[/color]
      </myns:Course>
      </myns:hasCourse>
      </myns:ProgrammeA I>
      </myns:hasProgram me>
      <myns:hasProgra mme
      rdf:resource="f ile:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Fo undationAI"/>
      <myns:hasProgra mme
      rdf:resource="f ile:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Ag entsLanguageSpe ech"/>
      </myns:University >
      </myns:isProgramm eOf>
      <myns:Programme Name rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
      >Agents, Language and Speech Technology</myns:ProgrammeN ame>[/color]
      </myns:ProgrammeA I>
      <myns:Programme AI rdf:ID="MenMach ine">
      <myns:hasCourse >
      <myns:Course rdf:ID="Advance dKnowledgeTechn ology">
      <myns:CourseECT S rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#float "[color=blue]
      >5.0</myns:CourseECTS >[/color]
      <myns:isCourseO f
      rdf:resource="f ile:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Me nMachine"/>
      <myns:CourseNam e rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
      >Advanced Knowledge Technology</myns:CourseName >[/color]
      </myns:Course>
      </myns:hasCourse>
      <myns:Programme Name rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
      >Mens-Machine Communicatie en Artificial Intelligence</myns:ProgrammeN ame>[/color]
      <myns:isProgram meOf>
      <myns:Universit y rdf:ID="Groning enRUG">
      <myns:hasProgra mme
      rdf:resource="f ile:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Me nMachine"/>
      <myns:Universit yName rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
      >Groningen(RUG) </myns:University Name>[/color]
      </myns:University >
      </myns:isProgramm eOf>
      </myns:ProgrammeA I>
      <myns:Programme AI rdf:ID="Artific ialIntelligence ">
      <myns:Programme Name rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g"[color=blue]
      >Artificial Intelligence</myns:ProgrammeN ame>[/color]
      <myns:hasCourse >
      <myns:Course rdf:ID="Logisch eTechniekeninde AI">
      <myns:CourseECT S
      rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#float ">5.0</myns:CourseECTS >
      <myns:isCourseO f
      rdf:resource="f ile:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Ar tificialIntelli gence"/>
      <myns:CourseNam e
      rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Logische Technieken
      in de AI</myns:CourseName >
      </myns:Course>
      </myns:hasCourse>
      <myns:isProgram meOf>
      <myns:Universit y rdf:ID="Amsterd amVU">
      <myns:hasProgra mme
      rdf:resource="f ile:/C:/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Ar tificialIntelli gence"/>
      <myns:Universit yName
      rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Amsterdam(VU )</myns:University Name>
      </myns:University >
      </myns:isProgramm eOf>
      </myns:ProgrammeA I>
      </rdf:RDF>


      Comment

      • Fredrik Henricsson

        #4
        Re: XSL Transformation of .owl file

        Apologies, the most important part of the OWL file was cut off.
        <myns:Programme AI rdf:ID="AgentsL anguageSpeech">
        <myns:isProgram meOf>
        <myns:Universit y rdf:ID="Utrecht UU">
        <myns:Universit yName
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Utrecht(U U)</myns:University Name>
        <myns:hasProgra mme>
        <myns:Programme AI rdf:ID="Cogniti veDynamics">
        <myns:isProgram meOf
        rdf:resource="f ile:/C:/Skola/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Ut rechtUU"/>
        <myns:Programme Name
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Cognitive
        Dynamics</myns:ProgrammeN ame>
        <myns:hasCourse >
        <myns:Course rdf:ID="Dynamic Semantics">
        <myns:isCourseO f
        rdf:resource="f ile:/C:/Skola/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Co gnitiveDynamics "/>
        <myns:CourseNam e
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Dynamic
        Semantics</myns:CourseName >
        <myns:isCourseO f>
        <myns:Programme AI
        rdf:ID="Foundat ionAI">
        <myns:isProgram meOf
        rdf:resource="f ile:/C:/Skola/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Ut rechtUU"/>
        <myns:Programme Name
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Foundatio n of
        AI</myns:ProgrammeN ame>
        <myns:hasCour se
        rdf:resource="f ile:/C:/Skola/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Dy namicSemantics"/>
        </myns:ProgrammeA I>
        </myns:isCourseOf >
        <myns:CourseECT S
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#float ">7.5</myns:CourseECTS >
        </myns:Course>
        </myns:hasCourse>
        </myns:ProgrammeA I>
        </myns:hasProgram me>
        <myns:hasProgra mme
        rdf:resource="f ile:/C:/Skola/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Fo undationAI"/>
        <myns:hasProgra mme
        rdf:resource="f ile:/C:/Skola/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Ag entsLanguageSpe ech"/>
        </myns:University >
        </myns:isProgramm eOf>
        <myns:Programme Name
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Agents, Language and
        Speech Technology</myns:ProgrammeN ame>
        </myns:ProgrammeA I>
        <myns:Programme AI rdf:ID="MenMach ine">
        <myns:hasCourse >
        <myns:Course rdf:ID="Advance dKnowledgeTechn ology">
        <myns:CourseECT S
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#float ">5.0</myns:CourseECTS >
        <myns:isCourseO f
        rdf:resource="f ile:/C:/Skola/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Me nMachine"/>
        <myns:CourseNam e
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Advanced Knowledge
        Technology</myns:CourseName >
        </myns:Course>
        </myns:hasCourse>
        <myns:Programme Name
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Mens-Machine
        Communicatie en Artificial Intelligence</myns:ProgrammeN ame>
        <myns:isProgram meOf>
        <myns:Universit y rdf:ID="Groning enRUG">
        <myns:hasProgra mme
        rdf:resource="f ile:/C:/Skola/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Me nMachine"/>
        <myns:Universit yName
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Groningen(RU G)</myns:University Name>
        </myns:University >
        </myns:isProgramm eOf>
        </myns:ProgrammeA I>
        <myns:Programme AI rdf:ID="Artific ialIntelligence ">
        <myns:Programme Name
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Artificia l
        Intelligence</myns:ProgrammeN ame>
        <myns:hasCourse >
        <myns:Course rdf:ID="Logisch eTechniekeninde AI">
        <myns:CourseECT S
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#float ">5.0</myns:CourseECTS >
        <myns:isCourseO f
        rdf:resource="f ile:/C:/Skola/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Ar tificialIntelli gence"/>
        <myns:CourseNam e
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Logische Technieken
        in de AI</myns:CourseName >
        </myns:Course>
        </myns:hasCourse>
        <myns:isProgram meOf>
        <myns:Universit y rdf:ID="Amsterd amVU">
        <myns:hasProgra mme
        rdf:resource="f ile:/C:/Skola/Utbytesgrejer/Advanced%20Know ledge%20Technol ogy/Exercise%205/MasterAI.owl#Ar tificialIntelli gence"/>
        <myns:Universit yName
        rdf:datatype="h ttp://www.w3.org/2001/XMLSchema#strin g">Amsterdam(VU )</myns:University Name>
        </myns:University >
        </myns:isProgramm eOf>
        </myns:ProgrammeA I>
        </rdf:RDF>


        Comment

        • Andy Dingley

          #5
          Re: XSL Transformation of .owl file

          > Thanks for the extensive response, I've just recently started with XML and[color=blue]
          > XSLT so it's much appreciated.[/color]

          This is so broken I don't know where to start !

          You just can't process an RDF document like this in XSLT.
          Teaching students in this way is just wrong, wrong, wrong.
          You're using entirely the wrong toolset here, it'll end badly, and you won't learn either technology. You'd be far
          better off being taught XSLT with some much simpler XML, then maybe processing this sort of document through Jena.

          It is a very bad way to teach you, if you're being taught XSLT and OWL simultaneously. I don't know how much you do
          know, but I know of no way in which these could be taught together.

          Unless you _understand_ XML (you really grok it), then I can't even begin to explain what OWL is about. If you're trying
          to work with OWL, then XSLT is the wrong tool to use. Unless you've got _some_ experience, I can barely even explain
          why it's difficult!

          So I'll assume you're new to the whole lot you're learning XML / XSLT. This is a good place to be - it's useful stuff.

          Don't worry about OWL though. I'm assuming you're being taught this because it's a substitute for DTDs. Now I have big
          reservations about this - OWL is quite complicated and it's going to scare the feet off any XML newbie. Particularly
          it's based around the RDF data model and you just can't process that (sensibly) with XSLT.

          As an XSLT text, then I recommend Michael Kay's book "XSLT"
          <http://www.amazon.co.u k/exec/obidos/ASIN/0764543814/codesmiths>

          Jeni Tennison's "Beginning XSLT" is also good, and perhaps better as an approachable tutorial
          <http://www.amazon.co.u k/exec/obidos/ASIN/1590592603/codesmiths>

          Sal Mangano's "XSLT Cookbook" is a valuable text for commercial developers with problems to fix, but it will terrify
          learners!


          Now I'm still unclear what you're being asked to do here.

          We can find the courses trivially

          <xslt:templat e name="extract-courses-details" >
          <ul>
          <xslt:for-each select="//ont:Course" >
          <li>
          <xslt:call-template name="extract-course-details" >
          <xslt:with-param name="Course" select="." />
          </xslt:call-template>
          </li>
          </xslt:for-each>
          </ul>
          </xslt:template>


          Then for your first example, we can use some simple "XML style" XSLT code to show the course details within this.

          <xslt:templat e name="extract-course-details" >
          <xslt:param name="Course" select="/.." />

          <!-- print CourseName -->
          <p>Course: <xslt:value-of select="$Course/ont:CourseName" /></p>

          <!-- print ProgrammeName (the quick hack way) -->
          <p>Programme: <xslt:value-of select="$Course/ont:isCourseOf//ont:ProgrammeNa me" /></p>

          </xslt:template>

          Now there are a few issues with this.

          First of all there are some cardinality issues (how many programmes can a course belong to etc). It's important to
          remember these when working with XML / XSLT because most code you write will be working with a node set (potentially
          many data items) and your natural assumption is often that you're only looking for one. Then one day your input data
          contains more than one, and your application barfs. So either be able to _prove_ that the cardinality is that of a
          single value, or else code it to deal correctly with the multiple sets. This is particularly the case for library code.


          <xslt:templat e name="extract-course-details" >
          <xslt:param name="Course" select="/.." />

          <!-- print CourseName -->
          <p>Course: <xslt:value-of select="$Course/ont:CourseName" /></p>

          <!-- find out which Programme Course belongs to (not quite so hacky) -->
          <xslt:variabl e name="Programme " select="$Course/ont:isCourseOf/*[1]" />

          <!-- print ProgrammeName -->
          <p>Programme: <xslt:value-of select="$Progra mme/ont:ProgrammeNa me" /></p>

          <!-- find out which University Programme belongs to -->
          <!-- print UniversityName -->
          <p>University : <xslt:value-of select="$Progra mme/ont:isProgramme Of/ont:University/ont:UniversityN ame" /></p>
          </xslt:template>

          So in the example above, I've coded it to _ONLY_ accept the first one (discarding others). Not only would we have to
          deal with the multiples through some form of loop, but we'd have to make sure that the Programme and University
          selections stayed in synchronisation (hence the use of the variable) - so if you can do, do it the simple way, but make
          sure that it's demonstrably valid to do so in the future as well.


          Now notice the use of "//" within the XPath expressions. This is a dangerous technique ! (it's less hazardous to use it
          at the start of an expression). It's rarely necessary to use it in an XML context - it's needed here because of the
          subclassing of <Programme> as <ProgrammeAI> There's no way to implement this in XSLT, so we have to use this
          "wildcard" approach. My skin crawls to do this - it's a huge source of future errors.

          It's likely to be reliable to do this here, because <ProgrammeNam e> is likely (a risky assumption!) to only ever apply
          to <Programme> A more sophisticated ontology (arguably better) might have a <name> property for each of these
          elements. Then my crude assumption would start to fail - it would depend on the scope of what <isCourseOf> can apply to.

          Incidentally, a couple of convention notes:

          - <programmeNam e> would be conventional, because properties begin with a lowercase as a human readability issue.

          - You don't need the data typing sprinkled all over the instance data.

          - Watch your indentation - it can make code readability much easier.



          So how do we solve the "big problem", that of how to process this whole model, cardinality and RDF issues too ?
          Well try this example template. I've commented what I could, so this is hopefully an example of "complex RDF-processing
          XML for people who already know some XML" that's useful to you.

          I'm sorry this example is so clunky - this sort of processing just doesn't fit XSLT's model.

          In contrast, the ECTS example would be pretty easy, because that's expressable in "simple XML"
          <xsl:for-each select="//myns:Course[myns:CourseECTS &gt; 5.0]" >

          Of course, some use of rdf:about or simply changing the serialiser to some other valid XML serialisations would break
          things again - you ought to be using a real RDF tool here (like Jena), not an XML tool.

          _Please_ post follow up comments to this. I'd like to know just what you're after and whether this is useful to you.





          <!--
          These have global scope, so we place them outside the templates

          Note that we have to account for the subclassing here, but after this we can ignore it.
          -->
          <xsl:variable name="All-Programmes" select="//myns:Programme | //myns:ProgrammeA I" />
          <xsl:variable name="All-Universities" select="//myns:University " />



          <xsl:template name="extract-course-details-for-RDF-model" >

          <xsl:param name="Course" select="/.." />


          Course: <xsl:value-of select="$Course/myns:CourseName " />


          <!-- The RDF-capable version -->
          <!--
          Find the set of Programmes for this Course

          These are any elements which are either children of isCourseOf or parents of hasCourse
          We can't test the element name itself, because of subclassing changing the element name

          We either find the Programme elements directly
          or we retrieve them via rdf:resource as an attribute of the hasCourse element
          -->
          <xsl:variable name="Programme s-for-Course" select="
          $Course/myns:isCourseOf/*
          | $All-Programmes [concat('#', @rdf:ID) = $Course/myns:isCourseOf/@rdf:resource]
          | $Course/parent::myns:ha sCourse/parent::*
          | $All-Programmes [concat('#', @rdf:ID) = $Course/parent::myns:ha sCourse/@rdf:resource]
          " />

          <ul>
          <xsl:for-each select="$Progra mmes-for-Course" >

          <!-- This is optional, but we often need to do it whenever we've nested two loops
          (as "." scopes to the inner loop)
          It also makes the code clearer to read -->
          <xsl:variable name="Programme " select="." />

          <li>
          Programme: <xsl:value-of select="$Progra mme/myns:ProgrammeN ame" />


          <!-- find out which University(s) this Programme belongs to -->
          <xsl:variable name="Universit ies-for-Programme" select="
          $Programme/myns:isProgramm eOf/*
          | $All-Universities[concat('#', @rdf:ID) = $Programme/myns:isProgramm eOf/@rdf:resource]
          | $Programme/parent::myns:ha sProgramme/parent::*
          | $All-Universities[concat('#', @rdf:ID) = $Programme/parent::myns:ha sProgramme/@rdf:resource]
          " />

          <!-- Just a frippery to make the display neater -->
          <xsl:choose>
          <xsl:when test="count($Un iversities-for-Programme) &gt; 1" >
          <ul>
          <xsl:for-each select="$Univer sities-for-Programme" >
          <li>Universit y: <xsl:value-of select="./myns:University Name" /></li>
          </xsl:for-each>
          </ul>
          </xsl:when>

          <xsl:when test="count($Un iversities-for-Programme) = 1" >
          <br />University: <xsl:value-of select="$Univer sities-for-Programme/myns:University Name" />
          </xsl:when>
          </xsl:choose>


          </li>
          </xsl:for-each>
          </ul>
          </xsl:template>







          Comment

          Working...