![]() |
| Utilities of WCX Editor WCXE utilities serve for support of XML document object update, insert and delete operations. It is a collection of functions or XSLT named templates. They update the current node and return new XML document. The following functions are available in xe_utils stylesheet. u:replace-current function replaces the current node with new nodes passed through parameter $new-nodes. If $new-nodes is empty node-set the current node will be deleted. u:append-after-current function appends $new-nodes after the current node. u:add-child-to-current function adds $new-nodes to the children of the current node u:add-child-to-current-top function adds $new-nodes at the beginning of the current node children list. u:current-up function has no parameters. It moves the current node position up. If the current node is the first node of its parent nothing will be done and empty document will be returned. Example, <xsl:variable name="new-doc">
<xsl:for-each select="document('old-doc.xml')/doc-items/item[5]">
<xsl:variable name="update-item">
<xsl:copy>
<xsl:for-each select="@*[name(.)!='my_attribute']"><xsl:copy/></xsl:for-each>
<xsl:attribute name="my_attribute"><!-- new value code --></xsl:attribute>
<xsl:copy-of select="node()"/>
</xsl:copy>
</xsl:variable>
<xsl:call-template name="u:replace-current">
<xsl:with-param name="new-nodes" select="$update-item"/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
The above code updates the value of my_attribute and returns new document. Notice that if item[5] doesn't exist the variable $new-doc will be empty node-set. |