Carried over from this thread where Template Driven Extraction(TDE) was mentioned as a way to retrieve values from a certain element.
Currently, I am attempting to create multiple TDE templates at once for a certain path. The code I used to to accomplish this is written below
xquery version "1.0-ml";
import module namespace tde = "http://marklogic.com/xdmp/tde"
at "/MarkLogic/tde.xqy";
let $t1 :=
<template xmlns="http://marklogic.com/xdmp/tde">
<context>/question</context>
<vars>
<var>
<name>EX</name>
<val>""</val>
</var>
</vars>
<triples>
<triple>
<subject>
<val>sem:iri( $EX || name)</val>
</subject>
<predicate>
<val>sem:iri("/has_tags")</val>
</predicate>
<object>
<val>xs:dateTime( $EX || tags)</val>
</object>
</triple>
</triples>
</template>
let $t2 :=
<template xmlns="http://marklogic.com/xdmp/tde">
<context>/question</context>
<vars>
<var>
<name>EX</name>
<val>""</val>
</var>
</vars>
<triples>
<triple>
<subject>
<val>sem:iri( $EX || name)</val>
</subject>
<predicate>
<val>sem:iri("/date_posted")</val>
</predicate>
<object>
<val>xs:dateTime( $EX || date_posted)</val>
</object>
</triple>
</triples>
</template>
return(
tde:template-insert("question_has_tags.xml",$t1, (), "http://marklogic.com/xdmp/tde"),
tde:template-insert("question_date_posted.xml",$t2, (), "http://marklogic.com/xdmp/tde")
)
A sample document
<?xml version="1.0" encoding="UTF-8"?>
<question>
<tags>uifontweighttrait,spark-thriftserver,alarmmanager,recursive-type,string-iteration,security-trimming,google-earth</tags>
<date_posted>1978-06-23T22:22:43</date_posted>
<name>/question_on_forum</name>
</question>
The template was tested using
tde:node-data-extract(fn:doc("/question"));
Which resulted in the error
[1.0-ml] TDE-EVALFAILED: tde:node-data-extract(fn:doc("/question/780989102826685")) -- Eval for Object='xs:dateTime( $EX || tags)' returns TDE-BADVALEXPRESSION: Invalid val expression: XDMP-CAST: (err:FORG0001) Invalid cast: "spotify,databags,laravel-horizon" cast as xs:dateTime
This error was solved the moment I removed one of the template
===========UPDATE===========
The codes below were used in an attempt to create multiple triples per template. However, it also results in the same error
xquery version "1.0-ml";
import module namespace tde = "http://marklogic.com/xdmp/tde"
at "/MarkLogic/tde.xqy";
let $t2 :=
<template xmlns="http://marklogic.com/xdmp/tde">
<context>/question</context>
<triples>
<triple>
<subject>
<val>sem:iri( uri)</val>
</subject>
<predicate>
<val>sem:iri("/date_posted")</val>
</predicate>
<object>
<val>xs:dateTime(date_posted)</val>
</object>
</triple>
</triples>
<triples>
<triple>
<subject>
<val>sem:iri(uri)</val>
</subject>
<predicate>
<val>sem:iri("/has_tags")</val>
</predicate>
<object>
<val>tags</val>
</object>
</triple>
</triples>
</template>
return(
tde:template-insert("question_date_posted.xml",$t2, (), "http://marklogic.com/xdmp/tde")
)
Node Extract for testing (This is where the error will occur)
xquery version "1.0-ml";
tde:node-data-extract(fn:doc("/question"));
Example Document Used
<?xml version="1.0" encoding="UTF-8"?>
<question>
<tags>jsondate,jmsserializerbundle,omnikey,eula,template-deduction,pyclipper,asyncpg,naming,kubeconfig,timer-trigger</tags>
<date_posted>1986-02-21T22:27:50</date_posted>
<uri>/question</uri>
</question>
xs:dateTime( $EX || tags), I think you just wanttagsthere. And this won't work either:xs:dateTime( $EX || date_posted), it would have to be$EX || xs:dateTime(date_posted), but I expect you want to usexs:dateTime(date_posted).. - grtjn<triples>element looks a bit overkill, but doesn't seem to throw a validate error. - grtjn