2010-01-29 22:13:57 +00:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
|
|
|
<xsl:stylesheet
|
|
|
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
2011-11-29 19:04:08 +00:00
|
|
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
|
|
xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"
|
2010-01-29 22:13:57 +00:00
|
|
|
version="2.0">
|
|
|
|
<xsl:output method="xml" indent="yes"/>
|
|
|
|
<!--
|
|
|
|
XSLT to produce RDF/XML from XML. This template does not handle
|
|
|
|
narrative content.
|
|
|
|
|
|
|
|
This uses XSLT 2.0 and XPath 2.0 so use Saxon.
|
|
|
|
Here is an example of how to do use XSLT 2.0 in ant:
|
|
|
|
|
|
|
|
<xslt style="${ingest.dir}/xsl/activityInsight2n3Rdf.xsl"
|
|
|
|
in ="${ingest.dir}/ai_xml/document1.xml"
|
|
|
|
out="${ingest.dir}/ai_xml/document1.n3"
|
|
|
|
<classpath location="${ingest.dir}/lib/saxon8.jar" />
|
|
|
|
|
|
|
|
Here is an example of how to run saxon from the command line:
|
|
|
|
java -Xmx512m -jar /home/bdc34/bin/saxon9he.jar \
|
|
|
|
-s:filteredbjltest1.xml -xsl:xsl/activityInsight2n3Rdf.xsl -o:filteredbjltest2.rdf
|
|
|
|
|
|
|
|
2009 Mann Library, Brian Caruso.
|
|
|
|
-->
|
|
|
|
|
|
|
|
<!-- This XSL will attempt to use URIs from namespaces that are found
|
2011-11-29 19:04:08 +00:00
|
|
|
in the XML document. If an Element lacks a namespace then this NS is used. -->
|
|
|
|
<xsl:variable name="defaultNS">http://ingest.mannlib.cornell.edu/generalizedXMLtoRDF/0.1/</xsl:variable>
|
2010-01-29 22:13:57 +00:00
|
|
|
|
|
|
|
<!-- This is a regular expression used to test then QNames of nodes. Any node
|
|
|
|
with a QName that matches this regex will have position dataproperties on each of
|
|
|
|
their children nodes -->
|
2011-11-29 19:04:08 +00:00
|
|
|
<xsl:param name="positionParentRegex" select="''"/>
|
|
|
|
|
2010-01-29 22:13:57 +00:00
|
|
|
<xsl:template match="/">
|
2011-11-29 19:04:08 +00:00
|
|
|
<rdf:RDF>
|
2010-01-29 22:13:57 +00:00
|
|
|
<xsl:apply-templates mode="rdfDescription" select="*"/>
|
|
|
|
</rdf:RDF>
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
<!-- create description elements -->
|
|
|
|
<xsl:template mode="rdfDescription" match="*">
|
2011-11-29 19:04:08 +00:00
|
|
|
<rdf:Description>
|
2010-01-29 22:13:57 +00:00
|
|
|
<xsl:element name="rdf:type">
|
|
|
|
<xsl:attribute name="rdf:resource"
|
|
|
|
select="concat((if(namespace-uri())then namespace-uri() else $defaultNS),local-name())"/>
|
|
|
|
</xsl:element>
|
2011-11-29 19:04:08 +00:00
|
|
|
<xsl:apply-templates select="*"/>
|
2010-01-29 22:13:57 +00:00
|
|
|
</rdf:Description>
|
|
|
|
</xsl:template>
|
|
|
|
|
2011-11-29 19:04:08 +00:00
|
|
|
<!-- Recursive tempate to turn Elements with Attributes and/or Text into bnodes -->
|
2010-01-29 22:13:57 +00:00
|
|
|
<xsl:template match="*">
|
2011-11-29 19:04:08 +00:00
|
|
|
<xsl:element
|
|
|
|
name="{ local-name() }"
|
|
|
|
namespace="{ (if(namespace-uri() and string-length(namespace-uri())>0 )then namespace-uri() else $defaultNS) }" >
|
2010-01-29 22:13:57 +00:00
|
|
|
<rdf:Description>
|
|
|
|
<xsl:apply-templates select="*|@*"/>
|
|
|
|
|
|
|
|
<xsl:if test="not(*) and string-length(text())>0">
|
|
|
|
<vitro:value><xsl:copy-of select="text()"/></vitro:value>
|
|
|
|
</xsl:if>
|
|
|
|
|
|
|
|
<xsl:if test="matches(../name(),$positionParentRegex) or
|
|
|
|
matches(concat(../namespace-uri(),../local-name()),$positionParentRegex)">
|
2011-11-29 19:04:08 +00:00
|
|
|
<vitro:position><xsl:value-of select="position()"/></vitro:position>
|
2010-01-29 22:13:57 +00:00
|
|
|
</xsl:if>
|
|
|
|
|
|
|
|
</rdf:Description>
|
|
|
|
</xsl:element>
|
|
|
|
</xsl:template>
|
|
|
|
|
2011-11-29 19:04:08 +00:00
|
|
|
<!-- Match all leaf Elements that have Attributes and/or Text and turn them into bnodes -->
|
|
|
|
<xsl:template match="*[not(*) and @* and string-length(text())>0]">
|
|
|
|
<xsl:element
|
|
|
|
name="{ local-name() }"
|
|
|
|
namespace="{ (if(namespace-uri() and string-length(namespace-uri())>0 )then namespace-uri() else $defaultNS) }" >
|
2010-01-29 22:13:57 +00:00
|
|
|
<rdf:Description>
|
|
|
|
<xsl:apply-templates select="@*"/>
|
|
|
|
<vitro:value>
|
|
|
|
<xsl:value-of select="."/>
|
|
|
|
</vitro:value>
|
|
|
|
</rdf:Description>
|
|
|
|
</xsl:element>
|
|
|
|
</xsl:template>
|
|
|
|
|
2011-11-29 19:04:08 +00:00
|
|
|
<!-- Match all attributes and turn them into data properties. -->
|
|
|
|
<xsl:template match="@*">
|
|
|
|
<xsl:element
|
|
|
|
name="{ local-name() }"
|
|
|
|
namespace="{ (if(namespace-uri() and string-length(namespace-uri())>0 )then namespace-uri() else $defaultNS) }" >
|
2010-01-29 22:13:57 +00:00
|
|
|
<xsl:value-of select="."/>
|
|
|
|
</xsl:element>
|
|
|
|
</xsl:template>
|
|
|
|
|
2011-11-29 19:04:08 +00:00
|
|
|
<!-- Match all Elements with only a text node and turn them into data properties. -->
|
|
|
|
<xsl:template match="*[not(*) and not(@*) and string-length(text())>0]">
|
|
|
|
<xsl:element
|
|
|
|
name="{ local-name() }"
|
|
|
|
namespace="{ (if(namespace-uri() and string-length(namespace-uri())>0 )then namespace-uri() else $defaultNS) }" >
|
|
|
|
<xsl:value-of select="."/>
|
|
|
|
</xsl:element>
|
|
|
|
</xsl:template>
|
2010-01-29 22:13:57 +00:00
|
|
|
|
|
|
|
</xsl:stylesheet>
|