Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Simple answer is "No". But there are of course ways forward.</p> <p>If you're amenable to adding an attribute (but leaving the element name unchanged), you could constrain the field by that, e.g.:</p> <pre><code>&lt;Device&gt; &lt;Name _field="DeviceName"&gt;device1&lt;/Name&gt; ... &lt;/Device&gt; </code></pre> <p>The attribute/value pair can be anything you want; you just have to tell the field definition, what it is. A good practice might be to <code>namespace-qualify</code> the attribute, so it's clearly an annotation from a different vocabulary, e.g.:</p> <pre><code>&lt;Device xmlns:field="http://example.com/field-annotations"&gt; &lt;Name field:name="DeviceName"&gt;device1&lt;/Name&gt; ... &lt;/Device&gt; </code></pre> <p>Range indexes can currently only be tied to element values, attribute values, and field values. Fields let you abstract a little bit from the underlying structure, but not as much as a more generic mechanism would.</p> <p>Another technique sometimes employed (though I haven't personally tried this) is to use two databases, one that's slightly more "logical" (e.g., a standard format, unchanged) and one that's more <code>database-optimized</code>.</p> <p>Whatever approach you decide, a little more work is necessary.</p> <p>If I were you, I'd probably write an <code>XSLT</code> transform which could be applied on input, and another simple one for returning the original unannotated version if I ever need it.</p> <p>annotate.xsl:</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:field="http://example.com/field-annotations"&gt; &lt;xsl:import href="copy.xsl"/&gt; &lt;!-- Annotate Device/Name as a field --&gt; &lt;xsl:template mode="add-att" match="Device/Name"&gt; &lt;xsl:attribute name="field:name" select="'DeviceName'"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>cleanup.xsl:</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:field="http://example.com/field-annotations"&gt; &lt;xsl:import href="copy.xsl"/&gt; &lt;!-- Delete all field:* attributes --&gt; &lt;xsl:template match="@field:*"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>copy.xsl:</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;!-- Don't add any attributes by default --&gt; &lt;xsl:template mode="add-att" match="*"/&gt; &lt;!-- recursively copy elements --&gt; &lt;xsl:template match="*"&gt; &lt;xsl:element name="{name()}" namespace="{namespace-uri()}"&gt; &lt;xsl:apply-templates select="@*"/&gt; &lt;xsl:apply-templates mode="add-att" select="."/&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;!-- copy attributes and child nodes --&gt; &lt;xsl:template match="@* | text() | comment() | processing-instruction()"&gt; &lt;xsl:copy/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>You can apply <code>annotate.xsl</code> using <code>xdmp:xslt-invoke()</code> in your application code for inserting documents into the database. Or you can configure <code>annotate.xsl</code> as a transformer in an Information Studio flow.</p> <p>When you want to retrieve the pristine doc, just call:</p> <pre><code>xdmp:xslt-invoke("cleanup.xsl", doc("my-doc.xml")) </code></pre> <p>But for most cases in regular application code, you don't need to clean up the document. Since, the presence of an extra attribute will rarely have any effect there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload