English 中文(简体)
在装入标志时,改变xml元素?
原标题:Change xml element while loading into Marklogic?

页: 1

<?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>

如何做到这一点 我是这样吗?

问题回答

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>

这只会在产生产出要素时产生。

第二,名称要素模板:

<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> 

您可在信息室或记录仪中使用这一风格。 • 要求记录仪在您的财产档案中使用这些线路:

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





相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签