Marklogic Content Pump generate multiple documents through XSLT transform -
this second question related marklogic content pump utility.
i ingesting single aggregated xml document multiple records marklogic content pump. expect the aggregate xml document transformed different format , content pump utility generate multiple xml document single input large xml document.?
example: aggregated input xml document:
<root> <data>bob</data> <data>vishal></data> </root>
expected output content pump : 2 documents different format:
document 1 :
<data1>bob</data1>
document 2
<data1>vishal</data1>
i using following xslt split above document 2 nodes:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="root"> <xsl:apply-templates select="data"></xsl:apply-templates> </xsl:template> <xsl:template match="data"> <data1><xsl:value-of select="."/></data1> </xsl:template> </xsl:stylesheet>
output:
<?xml version="1.0" encoding="utf-8"?> <data1>bob</data1> <data1>vishal</data1>
following xquery transform, calls above "xslt file" generate 2 nodes:
xquery version "1.0-ml"; module namespace example = "http://marklogic.com/example"; declare function example:transform( $content map:map, $context map:map ) map:map* { let $attr-value := (map:get($context, "transform_param"), "undefined")[1] let $the-doc := map:get($content, "value") let $let-output:= xdmp:xslt-invoke("/marklogic.rest.transform/simple-xsl/assets/transform.xsl", $the-doc ) return (map:put( $content, "value", $let-output ),$content) };
the above xquery transforms fails , returns error. so, how modify above xquery program generates , indexes multiple transformed xml documents single document?
mlcp command:
mlcp.sh import -host localhost -port 8040 \ -username admin -password admin \ -input_file_path ./parent-form.xml \ -transform_module /example/parent-transform.xqy \ -transform_namespace "http://marklogic.com/example" \ -transform_param "my-value" \ -output_collections people \ -output_permissions my-app-role,read,my-app-role,update
the transform provided returns single document containing multiple root elements. transform work, marklogic not allow inserting database, , throw xdmp-multiroot: document nodes cannot have multiple roots
.
there 2 ways solve that. simplest use /*
behind xdmp:xslt-invoke
. other solution use <xsl:result-document href="{generate-id()}.xml">
inside xslt. both cause $let-output
contain sequence instead of single document.
however, without further changes result in xdmp-conflictingupdates
, write multiple results @ 1 database uri. solve can clone $content map:map
small trick, , provide separate uris. instance this:
for $let-output @ $i in xdmp:xslt-invoke("/marklogic.rest.transform/simple-xsl/assets/transform.xsl", $the-doc )/* let $extra-content := map:map(document{$content}/*) let $_ := map:put($extra-content, "value", $let-output) let $_ := map:put($extra-content, "uri", concat($the-uri, '-', $i, '.xml') ) return $extra-content
note: transform function has return type of map:map*
, meaning can return 0 or more map:map's containing result.
hth!
Comments
Post a Comment