Loading TOC...

MarkLogic 9 Product Documentation
sem:triple

sem:triple(
   $subject_or_node as item(),
   [$predicate as xs:anyAtomicType],
   [$object as xs:anyAtomicType],
   [$graph as sem:iri?]
) as sem:triple

Summary

Creates a triple object, which represents an RDF triple containing atomic values representing the subject, predicate, object, and optionally graph identifier (graph IRI).

This function is a built-in.

Parameters
subject_or_node The triple's subject as an atomic value, or the whole triple as a node. If specifying a node as a triple, this function must be used as a single-parameter version (that is, you cannot specify a triple in this parameter and also use the other parameters).
predicate The triple's predicate.
object The triple's object.
graph The triple's graph IRI. This parameter is only available if you have specified a subject, predicate, and object, and is not available if you have specified an element as a triple in the first parameter.

Usage Notes

It is possible to create triples with sem:triple that might not be valid RDF triples. For example, you can create a triple with a blank node (sem:bnode()) as a predicate, even though that is not allowed in RDF. This is because the triples you can create with sem:triple are more general than what is allowed in RDF.

Example

xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
   at "MarkLogic/semantics.xqy";

sem:triple(sem:iri("subject"), sem:iri("predicate"), "object")

(: Returns the specified triple. :)

Example

xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
   at "MarkLogic/semantics.xqy";

sem:triple(
<sem:triple xmlns:sem="http://marklogic.com/semantics">
  <sem:subject>subject</sem:subject>
  <sem:predicate>predicate</sem:predicate>
  <sem:object
   datatype="http://www.w3.org/2001/XMLSchema#string">object</sem:object>
</sem:triple>)

(: Returns the specified triple. :)

Example

xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
   at "MarkLogic/semantics.xqy";

sem:triple(
  object-node {
    "triple" : object-node {
      "subject" : "subject",
      "predicate" : "predicate",
      "object" : object-node {
        "value" : "object",
        "datatype" : "http://www.w3.org/2001/XMLSchema#string"
      }
    }
  }
)

(: Returns the specified triple. :)

Example

xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
   at "MarkLogic/semantics.xqy";

sem:triple(
<foo>{sem:triple(sem:iri("subject"), sem:iri("predicate"),
      "object")}
</foo>/element())

(: Returns the specified triple. :)

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.