Loading TOC...

MarkLogic 12 EA 2 Product Documentation
op.xmlAttribute

op.xmlAttribute(
   name as String,
   value as String
) as attributeNode

Summary

This function constructs an XML attribute with the name (which can be a string or QName) and atomic value.

Parameters
name The attribute name.
value The attribute value.

Example

const op = require('/MarkLogic/optic');

const literals = op.fromLiterals([
            {row:1, gp: 1, nm:"alpha", str:"a", num:10, bool:true},
            {row:2, gp: 1, nm:"beta", str:"b", num:20, bool:false},
            {row:3, gp: 2, nm:"gamma", str:"c", num:30, bool:true},
            {row:4, gp: 2, nm:"delta", str:"d", num:40, bool:false}
	          ])
literals.select(['gp',
                 op.as('re', op.xmlElement('relem', [
                         op.xmlAttribute('row', op.col('row')),
                         op.xmlAttribute('nm', op.col('nm')),
                         op.xmlAttribute('num', op.col('num'))
                         ]))
               ])
        .groupBy('gp', op.sequenceAggregate('rs', 're'))
        .orderBy('gp')
        .select(op.as('container',
                      op.xmlElement('gelem',
	                                 op.xmlAttribute('group', op.col('gp')),
	                                 op.xmlElement('rows', op.col('rs'))
	                    ))
	             )
        .result();
  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.