简体   繁体   中英

Split XML file using Information Studio in MarkLogic

I need to split a XML file looking like the following

<root>
   <Credit>
       <TradeId>123</TradeId>
       <name>abcd</name>
   </Credit>
   <Credit>
       <TradeId>456</TradeId>
       <name>efgh</name>
   </Credit>
   <Credit>
       <TradeId>789</TradeId>
       <name>ijkl</name>
   </Credit>
</root>

into 3 separate files by the node Credit, each looking like the following:

<root>
   <Credit>
       <TradeId>123</TradeId>
       <name>abcd</name>
   </Credit>
</root>

Am using the following code in the XSLT (stylesheet version 2.0) transformation option in Information Studio in MarkLogic but it is not working. It is loading the original file instead of splitting it into smaller files and loading them.

<xsl:template match="/">
   <xsl:for-each select="collection(iri-to-uri('./?select=*.xml;recurse=yes'))">
     <xsl:for-each select="//Credit">
      <xsl:variable name="TradeId" select="TradeId" />          
          <xsl:variable name="filename" select="concat('./_Out/', $TradeId, .xml')" />
      <xsl:value-of select="$filename" />
      <xsl:result-document href="{$filename}">
          <root>
        <xsl:copy-of select="node()"/>
          </root>
      </xsl:result-document>
    </xsl:for-each>
   </xsl:for-each>
</xsl:template>

Am I missing something here? Thanks in advance!

The problem is caused by the fact that the ingested documents are loaded into a temporary database named ' Fab '. The XSLT transformation is applied in there. Results are moved to the target database at success. This moving of documents relies on information studio specific properties which get assigned automatically to the result of the main XSLT output, but not to any secondary output coming from xsl:result-document calls.

It is possible to replace the XSLT step with an XQuery step that explicitly copies these properties to all results, but that makes it depend on that specific version of information studio. It is much safer to copy the collector, and customize that to do the splitting.

There are some very good examples on Github: https://github.com/marklogic/infostudio-plugins

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM