<!DOCTYPE spec PUBLIC "-//W3C//DTD Specification V2.1//EN"
  "http://www.w3.org/XML/1998/06/xmlspec-v21.dtd" [
<!ENTITY iso6.doc.date "20000929">
<!ENTITY doc-type "xlink2rdf">
]>
<spec w3c-doctype="note">
<header>
<title>Harvesting RDF Statements from XLinks</title>
<w3c-designation>NOTE-&doc-type;-&iso6.doc.date;</w3c-designation>
<w3c-doctype>W3C Note</w3c-doctype>
<pubdate><day>29</day><month>September</month><year>2000</year></pubdate>
<publoc><loc href="http://www.w3.org/TR/2000/NOTE-&doc-type;-&iso6.doc.date;">http://www.w3.org/TR/2000/NOTE-&doc-type;-&iso6.doc.date;</loc></publoc>
<authlist>
 <author>
  <name>Ron Daniel Jr.</name>
  <affiliation>Metacode Technologies Inc.</affiliation>
  <email href="mailto:rdaniel@metacode.com">rdaniel@metacode.com</email>
 </author>
</authlist>
<abstract>
<p>Both XLink <bibref ref="XLink"/> and RDF <bibref ref="rdf"/> provide a way
of asserting relations between resources. RDF is primarily for describing
resources and their relations, while XLink is primarily for specifying and
traversing hyperlinks. However, the overlap between the two is sufficient
that a mapping from XLink links to statements in an RDF model can be defined.
Such a mapping allows XLink elements to be harvested as a source of RDF statements.
XLink links (hereafter, <quote>links</quote>) thus provide an alternate syntax
for RDF information that may be useful in some situations.</p>
<p>This Note specifies such a mapping, so that links can be harvested and
RDF statements generated. The purpose of this harvesting is to create RDF
models that, in some sense, represent the <emph>intent</emph> of the XML
document.
The purpose is <emph>not</emph> to represent the XLink structure in enough
detail that a set of links could be round-tripped through an RDF model.</p>
</abstract>
<status>
<p>This Note is made available by the W3C
<loc href="http://www.w3.org/XML/Activity#linking-wg">XML Linking Working Group</loc>
for the consideration of the XLink and RDF communities in the hopes that
it may prove useful. However, it is not a formal product of the XML
Linking Working Group. Thus, it should not be construed as representing
the consensus of the XML Linking Working Group. Comments should be sent
to the public mailing-list <loc href="mailto:www-rdf-interest@w3.org"
>www-rdf-interest@w3.org</loc>(<loc
href="http://lists.w3.org/Archives/Public/www-rdf-interest/"
>archive</loc>). However, readers are advised that the XML Linking Working
Group has no plans to update this document.
</p>
<p>A list of <loc href="http://www.w3.org/TR">current W3C Recommendations and
other technical documents</loc> is available.</p>
<p>Publication of this Note by W3C indicates no endorsement by
W3C or the W3C Team, or any W3C Members.</p>
</status>
<langusage>
<language>en-US</language>
</langusage>
<revisiondesc>
<slist>
<sitem>rd: Initial draft</sitem>
<sitem>elm: &ldquo;Clean-up&rdquo; draft with more precise Status section
and XLink terminology usage.</sitem>
<sitem>rd: Added XSLT appendix. Changed synthesized XPointers to use
       ChildSeq abbreviation. Minor cleanups.
</sitem>
<sitem>rd: Edits in light of last-call comments.</sitem>
</slist>
</revisiondesc>
</header>
<body>
<div1 id="introduction">
<head>Introduction</head>
<p>The XLink specification <bibref ref="XLink"/> defines ways for
XML documents to establish hyperlinks between resources. The Resource
Description Framework specification <bibref ref="rdf"/> defines a
framework for the provision of machine-understandable information
about web resources.</p>
<p>Both XLink and RDF provide a way of asserting relations between resources.
RDF is primarily for describing resources and their relations, while XLink
is primarily for specifying and traversing hyperlinks. However, the overlap
between the two is sufficient that a mapping from XLink links to statements
in an RDF model can be defined. Such a mapping allows XLink elements to be <termref
def="harvest">harvested</termref> as a source of RDF statements. XLink links
(hereafter, <quote>links</quote>) thus provide an alternate syntax for RDF
information that may be useful in some situations.</p>
<p>This Note specifies such a mapping, so that links can be harvested
and RDF statements generated. The purpose of this harvesting is to
create RDF models that, in some sense, represent the <emph>intent</emph>
of the XML document.  The purpose is <emph>not</emph> to represent the
XLink structure in enough detail that a set of links could be
round-tripped through an RDF model.</p>
<p>Readers of this Note are assumed to be familiar with
<bibref ref="XLink"/> and <bibref ref="rdf"/>. Terms that are defined
in those specifications will not be defined here. Readers should also
be familiar with XML Base <bibref ref="xbase"/>.
Familiarity with the RDF Schema Candidate Recommendation
<bibref ref="rdfs"/> will be necessary for those who wish to make
use of the mappings provided here that use RDF Schema Classes.</p>

<!-- ========================================== -->
<div2 id="terminology">
<head>Terminology</head>
<p><termdef id="dt-must" term="Must, May, etc.">The key words <term>must</term>, <term>
must not</term>, <term>required</term>, <term>shall</term>, <term>shall
not</term>, <term>should</term>, <term>should
not</term>, <term>recommended</term>, <term>may</term>, and
<term>optional</term> in this specification are to be interpreted
as described in <bibref ref="rfc2119"/>.</termdef></p>
<p>Some special terms are defined here in order to clarify
their relationship to similar terms used in the technologies
on which the mapping is based. Refer to <bibref ref="XLink"/> and
<bibref ref="rdf"/> for definitions of other technical
terms used here.</p>
<glist>
<gitem><label><termdef id="harvest" term="Harvesting">harvesting</termdef></label>
<def>
<p>The process of generating RDF statements from XLink elements.</p>
</def></gitem>
<gitem><label><termdef id="resource" term="resource">Resource</termdef></label>
<def>
<p>A <quote>resource</quote> is anything identified by a URI.</p>
</def></gitem>
<gitem><label><termdef id="participating_resource" term="participating
resource">Participating resource</termdef></label>
<def>
<p>A resource that has been identified in a link to serve as a
potential starting or ending point of traversal.</p>
</def></gitem>
</glist>
</div2>
<!-- ========================================== -->
<div2>
<head>Notation and Document Conventions</head>
<p>The <att>xlink:</att> and <att>rdf:</att> prefixes are used throughout
to stand for the declaration of the XLink and RDF namespaces, respectively,
on elements in whose scope the so-marked element or attribute appears (on
the same element or on some ancestor element), whether or not a namespace
declaration is present in the example. The use of specific namespace prefixes
is an editorial convienience; as dictated by the Names in XML
Recommendation <bibref ref="XML-Names"/>, any prefix
<termref def="dt-must">may</termref> be used
as long as the URI it maps to is the correct one.</p>
</div2>
<!-- ========================================== -->
</div1>
<div1 id="principles">
<head>Principles of the Mapping</head>
<p>Simple RDF statements are comprised of a subject, a predicate, and an object.
The subject and predicate are identified by URI references, and
the object may be a URI reference or a literal string. To map an
XLink link into an RDF statement, we need
to be able to determine the URI references of the subject and predicate. We must also
be able to determine the object, be it a URI reference or a literal.</p>
<p>The general principle behind the mapping specified here is that each arc
in a link gives rise to one RDF statement. The starting resource of the arc
is mapped to the subject of the RDF statement. The ending resource of the
arc is mapped to the object of the RDF statement. The arc role is mapped to
the predicate of the RDF statement. However, a number of corner cases arise,
described in <specref ref="spec"/>.</p>
<p>RDF statements are typically collected together into <quote>models.</quote>
The details of how models are structured are implementation dependent. This
Note assumes that harvested statements are added to <quote>the current
model,</quote> which is the model being constructed when the
statement was harvested.
But this Note, like <bibref ref="rdfs"/>, does not specify exactly how models
must be structured.</p>
</div1>
<!-- ========================================== -->
<div1 id="spec">
<head>Mapping Specification</head>
<p>The following sections describe the mapping in detail.</p>
<div2 id="xptr_synth">
<head>Synthesizing XPointers</head>
<p>RDF is based on the use of URIs for identifying resources. In XLink, the
linking element itself (in the case of a simple link) or a subelement of the
linking element (in the case of an extended link) often serves as one of the
participating resources in the link. This requires that we be able to
define URI references that identify those linking elements.
Those URI references
<termref def="dt-must">must</termref> follow the XPointer specification.
</p>
<p>Any legal XPointer that identifies the proper element is allowed.
However, in order that
different implementations harvest equivalent RDF statements from
an XLink, the procedure in this section <termref def="dt-must">
should</termref> be used when synthesizing XPointers for such
linking elements.
The general approach recommended is for the synthesized XPointer
to do element-wise navigation down the tree to reach the linking
element. The navigation begins at the nearest identified point
in the tree.</p>
<p>More formally, the base of the synthesized URI reference
<termref def="dt-must">shall</termref> be specified as defined
in <bibref ref="xbase"/>.</p>
<p>The fragment identifier of the synthesized URI reference
<termref def="dt-must">shall</termref> be delimited from the
URI by the '#' character, as
required by RFC 2396<bibref ref="rfc2396"/>. The fragment identifier
of the synthesized URI reference <termref def="dt-must">shall</termref>
be an XPointer<bibref ref="xptr"/>.</p>
<p>The XPointer <termref def="dt-must">should</termref> follow the
production:
<scrap>
<head>Recommended Syntax for Synthesized XPointers</head>
<bnf>
     XPointer    ::= Name
                   | ChildSeq

     ChildSeq    ::=  '/' [1-9] [0-9]* ('/' [1-9] [0-9]*)*
                   |  Name ('/' [1-9] [0-9]*)+ 
</bnf>
</scrap>
<note><p>This is an edited version of the 
<xnt href="http://www.w3.org/TR/xptr#NT-ChildSeq">ChildSeq</xnt>
production, assuming
that the production is updated in line with recent working group
discussions. In the case of any differences between this document and
the final XPointer specification, the XPointer specification's definition
of ChildSeq should be followed.</p>
</note>
</p>

<p>The initial locator term
of the XPointer <termref def="dt-must">should</termref> be an ID
reference to the nearest ancestor of the linking element, including
the linking element itself, that bears an attribute of type
<code>ID</code>. If no such attribute exists on any ancestor of
the linking element, the '/' character
<termref def="dt-must">should</termref> be the first linking term,
indicating that navigation proceeds from the document element.
</p>
<p>As an example, consider a document that contains the following
simple link:</p>
<eg>In heavy trading, &lt;org
  xlink:type='simple'
  xlink:href="http://www.foo.com/"
  xml:base="http://www.bar.com/report1"
  ID="com231"
>Foo Manufacturing&lt;/org> closed sharply lower...</eg>
<p>The synthesized XPointer for this linking element is:</p>
<eg>http://www.bar.com/report1#com231</eg>
</div2>
<!-- ========================================== -->
<div2 id="predicates">
<head>Generating RDF Predicates</head>
<p>Unless stated otherwise, RDF statements are generated to represent the
information for the arcs in a link. The value of
the <att>xlink:arcrole</att> attribute, if one
is given on an <attval>arc</attval>-type element or
<attval>simple</attval>-type element,
<termref def="dt-must">must</termref> be mapped to
the predicate of the RDF statement. Note that the value of
the <att>xlink:arcrole</att> attribute is already required,
by the XLink specification, to be a URI reference.
</p>
<p>If no <att>xlink:arcrole</att> attribute is specified,
harvesting software <termref def="dt-must">should not</termref> generate
an RDF statement. That is certainly the safest course. However, 
many XML files may not have arcrole attributes. Implementations that
wish to attempt to harvest RDF statements from such files
<termref def="dt-must">may</termref> map
the element type of the linking element to the predicate
of the RDF statement, as long as the element type is namespace
qualified. This ensures that an an absolute URI reference can
be constructed from the namespace
URI and the local part. In this case the namespace name and the
local part are concatenated to synthesize the absolute URI
reference for the predicate. Implementations 
<termref def="dt-must">should</termref> examine the namespace
URI to test if it ends in one of the URI characters '#', '?', or
'/'. If it does then the namespace URI and the local part 
<termref def="dt-must">shall</termref> be concatenated using the
simple approach documented in <bibref ref="rdf"/>. If the namespace
URI does not end in such a character, implementations
<termref def="dt-must">may</termref> create a URI reference by
inserting a '#' character. Note however that such URI references
<termref def="dt-must">must not</termref> be exchanged with external
parties, as they are not guaranteed to actually exist.
</p>
</div2>
<!-- ========================================== -->
<div2 id="simple_links">
<head>Simple Linking Elements</head>
<p>If a simple link's <att>xlink:arcrole</att> attribute has the
value <attval>http://www.w3.org/1999/xlink/properties/linkbase</attval>,
the link <termref def="dt-must">shall</termref> be harvested according
to section <specref ref="linkbases"/>.
Otherwise the mapping defined in this section
<termref def="dt-must">shall</termref> be used.</p>
<p>All simple links define zero or one traversal arcs. No traversal
arc is specified if the <att>xlink:href</att> attribute is not specified.
Therefore, harvesting software <termref def="dt-must">shall not</termref>
generate an RDF statements if there is no <att>xlink:href</att> attribute
in the link.</p>
<p>The starting resource of the simple link
<termref def="dt-must">shall</termref> be mapped to the
subject of the RDF statement. Note that the starting resource of a
simple link is the linking element itself. Therefore, the harvesting
software <termref def="dt-must">must</termref> create a URI
reference that identifies the linking element, as defined in 
section <specref ref="xptr_synth"/>.</p>
<p>The predicate of the RDF statement is obtained from the simple
Link as defined in <specref ref="predicates"/>.
</p>
<p>The ending resource of the simple link
<termref def="dt-must">shall</termref> be mapped to the object of
the RDF statement. Note that the ending resource
of a simple link is always a URI reference, provided as the value of
the <att>xlink:href</att> attribute.</p>

<!--  Edited the stuff above to try and clarify. Let me know. Ron
<ednote><name>
elm</name><edtext>The RFC 2119 stuff gets a bit ambiguous here. Is
it required to generate one statement if the element type is
namespace-qualified?</edtext>
</ednote>
-->

<p>If an <att>xlink:role</att> attribute is specified on the simple
link, it <termref def="dt-must">shall</termref> result in an
additional statement being added to the model. The subject of
the statement is the ending resource of the simple link,
its predicate is <quote><code>rdf:type</code></quote>, and its
object is the resource identified by the role attribute.
</p>
<p>If an implementation wishes to use facilities defined in the
RDF Schema specification <bibref ref="rdfs"/>, it
<termref def="dt-must">may</termref> add a second statement to the
RDF model when an <att>xlink:role</att> attribute is specified.
The subject of the second statement is the resource identified by
the <att>role</att> attribute, its predicate is
<quote><code>rdf:type</code></quote>, and its object is the
resource <quote>rdfs:Class</quote>. The second statement
<termref def="dt-must">should</termref> only be added to
the model if an equivalent statement is not already part of the
model.</p>
<p>An example of a simple linking element is:</p>
<eg>... In a &lt;x:extRef
  xlink:type="simple"
  xlink:href="http://www.foo.com/papers/crops.txt"
  xlink:arcrole="http://links.org/namespace/cite"
  xlink:role="http://links.org/namespace/screed"
>recent paper&lt;/x:extRef>, Dr. Taylor assumes that ...</eg>
<p>Mapping that link according to this specification (and assuming it was
the fourth child element within the third child element of the document)
results in the RDF model shown below:</p>
<graphic source="xlink2rdf-fig1.gif"/>
<p>If the <att>xlink:role</att> attribute had not been specified, then
the result would have been the RDF model shown below:</p>
<graphic source="xlink2rdf-fig2.gif"/>
</div2>
<!-- ========================================== -->
<div2 id="extended_links">
<head>Extended XML Links</head>
<ednote>
<name>ron</name>
<edtext>Does this make any sense for an extended linking element to be
a linkbase? Shouldn't it be arcs within the element that might be
linkbase references?
</edtext>
</ednote>
<p>We first describe the rules for harvesting the components of an
extended link (arcs, locators, and resources). Then we describe the
rules for the extended link as a whole.</p>
<!-- ========================================== -->
<div3 id="arcs">
<head><el>arc</el>-Type Element</head>
<p>If an arc contains an <att>xlink:arcrole</att> attribute whose
value is <attval>http://www.w3.org/1999/xlink/properties/linkbase</attval>,
it <termref def="dt-must">shall</termref> be harvested according to the
procedure in section <specref ref="linkbases"/>. Otherwise the procedures
in this section <termref def="dt-must">shall</termref> be used.
</p>
<p>
XLink elements of the <el>arc</el> type use the <att>xlink:to</att>
and <att> xlink:from</att> attributes to specify the endpoints of
zero or more possible traversals by referencing, not URIs, but
rather labels that have been defined in the <att>xlink:label</att>
attributes of <el>locator</el>-type and <el>resource</el>-type elements.
</p>
<p>
The number of RDF statements harvested from a single <el>arc</el>-type
element is equal to the number of possible traversals specified by that
element.
That quantity is the multiplicative product of the number of resource and/or
locator elements identified by the <att>xlink:to</att> and <att>xlink:from
</att> attributes. Each RDF statement will correspond to one and only one
of the traversals.
</p>
<p>
The starting resources of the traversals
<termref def="dt-must">shall</termref> be mapped to the subject of
the RDF statement(s). The ending resources of
the traversals <termref def="dt-must">shall</termref> be mapped to
the object of the RDF statement(s). The predicate of the RDF statement
is obtained as specified in <specref ref="predicates"/>.
</p>
<p>Note that any element content of an arc is not harvested.</p>
</div3>
<!-- ========================================== -->
<div3 id="locators">
<head><el>locator</el>-Type Element</head>
<p>Each XLink <el>locator</el>-type element gives rise to zero or
more statements in the RDF model. The subject of all of those
statements is the value of the <att>xlink:href</att> attribute of
the locator, except as noted below.
</p>
<p>
If the locator element provides an <att>xlink:role</att> attribute,
one additional statement <termref def="dt-must">shall</termref> be
added to the model. The value of the locator's <att>xlink:href</att>
attribute <termref def="dt-must">shall</termref> be mapped to the
subject of the statement. The value of the <att>xlink:role</att>
attribute <termref def="dt-must">shall </termref> be mapped to the
object, and the predicate <termref def="dt-must"> shall</termref>
be <quote>rdf:type</quote>. Harvesting software that uses the
facilities of the RDF Schema specification <termref def="dt-must">
may</termref> generate an additional statement whose subject is the
value of the <att>xlink:role</att> attribute, whose predicate is
<quote>rdf:type</quote> and whose object is <quote>rdfs:Class</quote>.
The second statement <termref def="dt-must">should not</termref> be
added to the RDF model if an equivalent statement already exists in
the model.
</p>
<!-- softened condition from 'must not' to 'should not'
<ednote>
<name>Ron</name>
<edtext>I'm considering pulling out this last condition, because it
is a pain to try and handle that in XSLT. The whole issue of
repeating properties in RDF models is not really well-defined
to the best of my recollection.
</edtext>
</ednote>
-->
<p>
If the locator element provides an <att>xlink:label</att> attribute, an
RDF statement is added to the model. The value of the href attribute <termref
def="dt-must">shall</termref> be mapped to the subject of the statement. The
predicate of the statement <termref def="dt-must">shall</termref> be <code>
xlink:label</code>. The object of the statement <termref def="dt-must">shall
</termref> be the value of the <att>xlink:label</att> attribute.
</p>
<p>If the locator element provides an <att>xlink:title</att> attribute, an
RDF statement <termref def="dt-must">shall</termref> be added to the model.
The value of the <att>xlink:href</att> attribute <termref def="dt-must">shall
</termref> be mapped to the subject of the statement. The predicate of the
statement <termref def="dt-must">shall</termref> be
<quote><att>xlink:title</att></quote>.
The object of the statement <termref def="dt-must">shall</termref> be the
value of the title attribute.
</p>
<p>If the resource element contains one or more title elements, they
are harvested as described in section <specref ref="titles"/>.</p>
</div3>
<!-- ========================================== -->
<div3 id="resources">
<head><el>resource</el>-Type Element</head>
<p>Each XLink <el>resource</el>-type element gives rise to zero or
more statements in the RDF model. Unless noted
otherwise, the subject of all of those statements is the resource element
itself, identified by an XPointer synthesized according to the procedure described
in section <specref ref="xptr_synth"/>.</p>
<p>If the resource element provides an <att>xlink:role</att> attribute, one
RDF statement <termref def="dt-must">shall</termref> be added to the model,
and a second RDF statement <termref def="dt-must">may</termref> be added to
the model. The subject of the first statement is the synthesized URI reference
for the resource. The value of the xlink:role attribute is mapped to the object
of the statement. The predicate of the statement is '<att>rdf:type</att>'.
A second statement <termref def="dt-must">may</termref> be added to the model
if the software supports the RDF Schema specification <bibref ref="rdfs"/>.
The value of the <att>xlink:role</att> attribute is mapped to the subject
of the optional statement. The predicate of the statement is <quote>rdf:type
</quote> and the object is <quote>rdfs:Class</quote>. The second
statement <termref def="dt-must">should not</termref> be added to the
model if an identical statement already exists in the model.
</p>
<p>If the resource element provides an <att>xlink:label</att> attribute,
another RDF statement <termref def="dt-must">shall</termref> be added to
the model. The subject of the statement is the synthesized URI reference
for the resource. The predicate of the statement is
<quote>xlink:label</quote>. The object of the statement is the value of
the label attribute.
</p>
<p>If the resource element provides an <att>xlink:title</att> attribute, another
RDF statement <termref def="dt-must">shall</termref> be added to the model.
The subject of the statement is the synthesized URI reference for the resource.
The predicate of the statement is <quote>xlink:title</quote>. The object of
the statement is the value of the title attribute.</p>
<p>If the resource element contains one or more title elements, they are harvested
as described in section <specref ref="titles"/>.</p>
</div3>
<!-- ========================================== -->
<div3 id="titles">
<head><el>title</el>-Type Element</head>
<p>XLink <el>title</el>-type elements have an XLink-defined meaning
only if they appear as a child element within an extended, locator,
or resource element.
<!-- I think not, but laziness plays a large role in that thinking. Ron.
<ednote>
<name>elm</name>
<edtext>Should we qualify all the other descriptions of XLink
elements this way, too?
</edtext>
</ednote>
-->
</p>
<p>If an XLink <el>extended</el>-, <el>locator</el>-, or
<el>resource</el>-type element contains one or more
<el>title</el>-type elements, one RDF statement <termref
def="dt-must">shall</termref> be added to the model for each
title element.
The subject of the statement <termref def="dt-must">shall</termref>
be either the value of the <att>xlink:href</att> attribute (in the
case of a <el>locator</el> element) or a synthesized XPointer identifying
the <el>extended</el> or <el>resource</el> element. The predicate
of the statement
<termref def="dt-must">shall</termref> be <code>xlink:title</code>. 
The object of the statement
<termref def="dt-must">shall</termref> be a synthesized XPointer
identifying the title element. (Identifying the title element, rather
than just its content, allows attributes such as <att>xml:lang</att>
to be captured along with the title.)
</p>
<note>
<p>
Implementations <termref def="dt-must">may</termref> add a second
RDF statement to the model for each <el>title</el>-type element. 
The object of the second statement shall be a synthesized XPointer
identifying the title element. The predicate of the second statement
shall be <code>rdf:value</code>. The object of the second statement 
shall be the content of the title element. (If the title element
contains mixed content, the object is a string containing XML markup.
The implementation's facilities for dealing with situations
where the <att>rdf:parseType</att> attribute has the value
<attval>literal</attval> will be needed.)
</p>
</note>
<p>As an example, consider the following fragment of an extended
link:</p>
<eg>&lt;annotation xlink:type='extended' ID='genid22'>
  &lt;caption xlink:type='title' ID='genid23'>&lt;i&gt;Recent&lt;/i> comments&lt;/caption>
  &lt;link xlink:type='arc' ...</eg>
<p>The RDF statements harvested from the title are shown below:</p>
<graphic source="xlink2rdf-fig3.gif"/></div3>
<!-- ========================================== -->
</div2>
<!-- ========================================== -->
<div2 id="linkbases">
<head>Linkbases</head>
<p>A linkbase is an XML document which functions like a database of
links. A linkbase arc is an XLink element (<el>simple</el>- or
<el>arc</el>-type) whose <att>xlink:arcrole</att> attribute takes the value
of <attval>http://www.w3.org/1999/xlink/properties/linkbase</attval>.
The ending resource of a linkbase arc is a linkbase.</p>
<p>When harvesting software encounters a linkbase arc, it
<termref def="dt-must">shall not</termref> generate an RDF statement for
the arc. It <termref def="dt-must">should</termref> traverse the arc to
retrieve the linkbase, and harvest the links from the linkbase to add to
the current model using the methods specified in this Note.</p>
<note>
<p>Different applications might make different tradeoffs on depth of
traversal in light of varying network conditions. This Note does not
mandate specific behavior, but does <termref def="dt-must">recommend
</termref> that all havesting applications attempt to obtain at
least the immediately referenced linkbase.
</p>
</note>
</div2>
<!-- ========================================== -->
</div1>
<!-- ========================================== -->
<div1 id="bibliography">
<head>References</head>
<blist>
<bibl id="XLink" href="http://www.w3.org/TR/xlink" key="XLink"><?Pub Dtl ?>
Steve DeRose, Eve Maler, David Orchard, and Ben Trafford, editors. <titleref>
XML Linking Language (XLink)</titleref>. World Wide Web Consortium, 2000.
</bibl>

<bibl id="XML-Names" href="http://www.w3.org/TR/REC-xml-names"
key="XML-Names"><?Pub Dtl ?>Tim Bray, Dave Hollander, and Andrew Layman, editors. <titleref>
Namespaces in XML</titleref>. Textuality, Hewlett-Packard, and Microsoft.
World Wide Web Consortium, 1999.</bibl>

<bibl id="rfc2119" key="IETF RFC 2119"><?Pub Dtl ?>S. Bradner, editor. <titleref>
Key words for use in RFCs to Indicate Requirement Levels</titleref>. March
1997. (See <loc href="http://www.ietf.org/rfc/rfc2119.txt">http://www.ietf.org/rfc/rfc2119.txt
</loc>.)</bibl>

<bibl id="rdf" href="http://www.w3.org/TR/REC-rdf-syntax"
key="RDF">Ora Lassila and Ralph Swick, editors. <titleref>Resource Description
Framework (RDF) Model and Syntax Specification</titleref>. World Wide Web
Consortium, 1999.</bibl>

<bibl id="xptr" href="http://www.w3.org/TR/xptr" key="XPTR"><?Pub Dtl ?>Ron
Daniel, Steve DeRose, and Eve Maler, editors.<titleref> XML Pointer Language
(XPointer) V1.0</titleref>. World Wide Web Consortium, 1998.
</bibl>

<bibl id="rfc2396" href="http://www.ietf.org/rfc/rfc2396.txt" key="RFC 2396">
RFC 2396: Uniform Resource Identifiers. Internet Engineering Task Force,
1995.</bibl>

<bibl id="rdfs" href="http://www.w3.org/TR/rdf-schema" key="RDFSchema">
Dan Brickley, R.V. Guha, editors. <titleref>Resource Description
Framework (RDF) Schema Specification 1.0</titleref>. World Wide Web
Consortium, 2000.
</bibl>

<bibl id="xbase" href="http://www.w3.org/TR/xmlbase"
key="XML Base"><?Pub Dtl ?>Jonathan Marsh, editor. <titleref>XML Base (XBase)
</titleref>. World Wide Web Consortium, 1999.</bibl>
</blist>
</div1>
</body>
<!-- ========================================== -->
<back>
<div1 id="xslt">
<head>Implementing the Harvesting in XSLT</head>
<p>One way of harvesting RDF statements from XML documents that contain
XLinks is through the use of XSLT. This appendix presents a simple
example of such a harvester. It has a number of limitations. It does
not generate the synthesized XPointers which are preferred for reasons
of interoperability. Second, it uses a Java extension function for
adding statements to an RDF storage manager. There is no standard API
for such a storage manager. Accordingly,
this appendix is provided as an example only. It does not
specify any normative behavior.</p>
<p>
The stylesheet itself is given in listing 1. Its operation is
very simple. It looks for simple XLinks, stores the subject, object,
and predicate in variables, then calls an extension function to add
the RDF statement to some storage mechanism.
</p>
<p>
<eg xml:space="preserve">
<![CDATA[
<!--

  Simple XSLT stylesheet to harvest RDF statements from simple
  XLinks. XLinks are detected and an extension function called
  to add RDF statements to an RDF repository. The extension function
  is a very simple mockup that just prints its arguments to stdout.

  Note that the repository is updated as a side effect of
  examining the document. While practical, this is somewhat at odds
  with the philosophy behind XSLT. Any application that actually
  cares about the order in which RDF statements are made is
  cautioned about using this approach.

  Credit where due: I got a head start on this by using Dan Connolly's 
  stylesheet that tried to turn XLinks into RDF's XML syntax.

  Ron Daniel Jr.
  rdaniel@metacode.com   2000-09-15
-->

<xsl:stylesheet 
    version="1.0"
    xmlns:xsl  ="http://www.w3.org/1999/XSL/Transform"
    xmlns:rdf  ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:rdfs ="http://www.w3.org/TR/rdf-schema/"

    xmlns:Radix="http://www.example.com/com.example.Radix"
>

  <!-- Some 'useful' declarations. -->
  <xsl:variable name='rdf-type'
	      select='"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"'/>
  <xsl:variable name='rdfs-class'
	      select='"http://www.w3.org/TR/rdf-schema#Class"'/>

  <xsl:output method="text"/>

  <!-- Look for simple links that are linkbase references, ignore them.
       (This rule is explicitly given a higher priority
        than the system-assigned priorities of the other rules so
        that it will match and discard linkbase references.)
  -->
  <xsl:template priority="2"
       match='*[@xlink:type="simple"][@xlink:arcrole=
               "http://www.w3.org/1999/xlink/properties/linkbase"]'>
      <!-- For now, do nothing. A more complete example could pull in
           the linkbase and harvest its content.
      -->
  </xsl:template>


  <!-- Process the simple links that are not linkbase references.
       Pull the various bits of info into variables and then call the
       extension function.
       (Make sure that we have an href specified. If not, there is no
       arc to add to the RDF model.)
  -->
  <xsl:template match='*[@xlink:type="simple"][@xlink:href]'>

    <!-- Subject - Synthesizing the XPointer in an interoperable way is
         left for more ambitious examples. For simplicity, just generate
         a unique ID.
    -->
    <xsl:variable name='subject'
		  select='concat("#xpointer-for-", generate-id())'/>

    <!-- Predicate name comes from arcrole (preferred) or element type
	 (allowed). Look for arcrole, but if it doesn't exist, use
	 element name. (Note that we have to concatenate the namespace
         URI and the local name according to the RDF spec to make a URI
         reference. This should really test to see if namespace URI
         ends with #, /, or ?)
     -->
    <xsl:variable name='predicate'>
      <xsl:choose>
        <!-- Get arcrole attribute if possible. -->
	<xsl:when test='@xlink:arcrole'>
	  <xsl:value-of select='@xlink:arcrole'/>
	</xsl:when>
        <!-- If no arcrole, use element type as long as there is a
             namespace URI so it can be made into a URI reference.
        -->
	<xsl:when test='namespace-uri()'>
	  <xsl:value-of select='concat(namespace-uri() , name())'/>
	</xsl:when>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name='object' select='string(@xlink:href)'/>
    <xsl:variable name='objType' select='string(@xlink:role)'/>

    <!--  Here it is - the main call to add a statement to the
          RDF database.
    -->
    <xsl:if test='$predicate'>
      <xsl:value-of select='Radix:addStatement($subject,
	       string($predicate), $object)'/>
    </xsl:if>

    <!-- Additional call if xlink:role specified. (We rely on the
         underlying RDF storage implementation to deal with possible
         multiple additions of the  rdf:type(objType, rdfs:Class)
         statement).
    -->
    <xsl:if test='$objType'>
      <xsl:value-of select='Radix:addStatement($object,
	       $rdf-type, $objType)'/>
      <xsl:value-of select='Radix:addStatement($objType,
	       $rdf-type, $rdfs-class)'/>
    </xsl:if>
  </xsl:template>


  <!-- don't pass text thru -->
  <xsl:template match="text()|@*">
  </xsl:template>

</xsl:stylesheet>
]]>
</eg>
</p>
<p>The stylesheet makes use of an extension function,
<code>Radix:addStatement(subject, predicate, object)</code>, which
would actually add the statement to an RDF storage manager. For
demonstration purposes, a dummy implementation of that extension
function is given in listing 2. This was tested using the Saxon
implementation of XSLT. Other implementations may have different
conventions for the use of extension functions.
</p>
<p>
<eg xml:space="preserve">
<![CDATA[
package com.example;
/** Simple demo of a RDF interface. This one is trivial, it has
  * one call that lets statements be added.
  */
public class Radix
{

  /** Mockup of a routine to add RDF statements to a model being
    * constructed. Prints the subject, predicate, and object on 
    * different lines with progressive indention to make it easy
    * to read.
    */
  public static String
  addStatement(String subject, String predicate, String object)
  {
    System.out.println(predicate + "\n  " + subject + "\n    " + object);
    return "";
  }
}
]]>
</eg>
</p>

</div1>
</back>
</spec>
<?Pub *0000027416 ?>
