Next: , Up: Node Constructors   [Contents]


3.1 Primitive Constructors

The constructors in this section can be thought of as primitives corresponding to their XSLT node-based counterparts: xsl:element, xsl:text, and xsl:comment. They can be arbitrarily nested to create tree structures.

  <sequence select="n:element( QName( 'ns', 'foo' ),
                               ( n:attr( QName( 'ns', 'attr1' ), 'value1' ),
                                 n:attr( QName( 'ns', 'attr2' ), 'value2' ) ),
                               ( n:text( 'Nest to create trees' ),
                                 n:comment( 'functional nodes' ),
                                 n:element( QName( 'ns', 'bar' ) ) ) )" />

Figure 3.1: Generating an XML tree using the primitive constructors

Consider Figure 3.1, which will output the following tree:

<foo attr1="value1" attr2="value2">Nest to create trees<!-- functional nodes --><bar /></foo>

Newlines are not automatically added.

function: element() n:element (qname as xs:QName, attrs as attribute()*, child-nodes as node()*)

xmlns:n="http://mikegerwitz.com/hoxsl/node"

Construct an element named qname with attributes attrs and child nodes children. An empty sequence may be provided if no attributes or children are desired (see also the unary and binary overloads).

Definition:

<function name="n:element"  as="element()">
  <param name="qname"  as="xs:QName" />
  <param name="attrs"  as="attribute()*" />
  <param name="child-nodes"  as="node()*" />

  <variable name="element"  as="element()">
    <element name="{$qname}"  namespace="{namespace-uri-from-QName( $qname ) }">
      <sequence select="$attrs, $child-nodes" />
    </element>
  </variable>

  <sequence select="$element" />
</function>
function: element() n:element (qname as xs:QName, attrs as attribute()*)

xmlns:n="http://mikegerwitz.com/hoxsl/node"

Construct an element named qname with attributes attrs and no child nodes. An empty sequence may be provided if no attributes are desired (see also the unary overload).

This is equivalent to n:element( $qname, $attrs, () ); see n:element#3.

Definition:

<function name="n:element"  as="element()">
  <param name="qname"  as="xs:QName" />
  <param name="attrs"  as="attribute()*" />

  <sequence select="n:element( $qname, $attrs, () )" />
</function>
function: element() n:element (qname as xs:QName)

xmlns:n="http://mikegerwitz.com/hoxsl/node"

Construct an element named qname with no attributes or children.

This is equivalent to n:element( $qname, (), () ); see n:element#3.

Definition:

<function name="n:element"  as="element()">
  <param name="qname"  as="xs:QName" />

  <sequence select="n:element( $qname, () )" />
</function>
function: attribute() n:attr (qname as xs:QName, value as xs:anyAtomicType)

xmlns:n="http://mikegerwitz.com/hoxsl/node"

Construct an attribute named qname with the value value.

Definition:

<function name="n:attr"  as="attribute()">
  <param name="qname"  as="xs:QName" />
  <param name="value"  as="xs:anyAtomicType" />

  <!-- some trickery (if there's a better way, lmk) -->
  <variable name="tmp-container"  as="element()">
    <element name="tmp">
      <attribute name="{$qname}"  namespace="{namespace-uri-from-QName( $qname ) }"  select="$value" />
    </element>
  </variable>

  <!-- there will only be one -->
  <sequence select="$tmp-container/@*" />
</function>
function: attribute() n:attr (qname as xs:QName)

xmlns:n="http://mikegerwitz.com/hoxsl/node"

Construct an attribute named qname with an empty value.

Definition:

<function name="n:attr"  as="attribute()">
  <param name="qname"  as="xs:QName" />

  <sequence select="n:attr( $qname, '' )" />
</function>
function: text() n:text (text as xs:string)

xmlns:n="http://mikegerwitz.com/hoxsl/node"

Create a text node with the given text. The text will be output verbatim without any whitespace processing.

Definition:

<function name="n:text"  as="text()">
  <param name="text"  as="xs:string" />

  <variable name="text-node"  as="text()">
    <value-of select="$text" />
  </variable>

  <sequence select="$text-node" />
</function>
function: comment() n:comment (text as xs:string)

xmlns:n="http://mikegerwitz.com/hoxsl/node"

Create a comment node with the given text. The text will be output verbatim without any whitespace processing.

Definition:

<function name="n:comment"  as="comment()">
  <param name="text"  as="xs:string" />

  <variable name="comment"  as="comment()">
    <comment select="$text" />
  </variable>

  <sequence select="$comment" />
</function>

Next: , Up: Node Constructors   [Contents]