2
votes

I have the following xml:-

<?xml version="1.0" encoding="UTF-8"?>
<patent-assignment>
 <patent-assignors>
    <patent-assignor>
      <name>TSAI, YU-WEN</name>
    </patent-assignor>
  </patent-assignors>
  <patent-assignees>
    <patent-assignee>
      <name>FARADAY TECHNOLOGY CORP.</name>
    </patent-assignee>
  </patent-assignees>
</patent-assignment>

Now while loading this xml document into Marklogic I want to change patent-assignor's name element into assignor-name and patent-assignee's name element into assignee-name so that my loaded xml should look like this:-

<?xml version="1.0" encoding="UTF-8"?>
    <patent-assignment>
     <patent-assignors>
        <patent-assignor>
          <assignor-name>TSAI, YU-WEN</assignor-name>
        </patent-assignor>
      </patent-assignors>
      <patent-assignees>
        <patent-assignee>
          <assignee-name>FARADAY TECHNOLOGY CORP.</assignee-name>
        </patent-assignee>
      </patent-assignees>
    </patent-assignment>

How Can I do this Marklogic ?

2

2 Answers

1
votes

I suggest taking a look at Information Studio. Here is the link to the 5-minute walk-through:

http://community.marklogic.com/learn/5-minute-infostudio-walkthrough

The Information Studio allows you to select a input collector, apply any number of transforms (you can enter XSLT or XQuery code from within the interface), select any target database, and even tweak things like uri that needs to be assigned, all from within that interface.

HTH!

0
votes

XSLT is perfect for this. Since you only want to change one element you need only create a stylesheet two simple templates. First, an identity transform:

<xsl:template match="node() | @*">
<xsl:apply-templates match="node() | @*">
</xsl:template>

This will simply output elements exactly as they come in.

Second, a template for the name element:

<xsl:template match="name">
<xsl:choose>
<xsl:when test="local-name(parent::element())='patent-assignee'">
<patent-assignee>
<xsl:value-of select="."/>
</patent-assignee>
</xsl:when>
<xsl:when test="local-name(parent::element())='patent-assignor'">
<patent-assignor>
<xsl:value-of select="."/>
</patent-assignor>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template> 

You can use this stylesheet in information studio or with recordloader. To call from recordloader use these lines in your properties file:

CONFIGURATION_CLASSNAME=com.marklogic.recordloader.xcc.DelimitedDataConfiguration
CONTENT_FACTORY_CLASSNAME = com.marklogic.recordloader.xcc.XccModuleContentFactory
CONTENT_MODULE_URI = /path/to/module.xqy

Then call your xslt from module.xqy