XML Commands (and examples)

Note: Reactivate this note every time. Annoying, but I am trying to make sur you only do what you really want to do...

AppendText

ParameterExample value
xmlTargetitem
xmlValueconcat('Setting text to ',tb:property('Name'))

set the text of each target node to the result of evaluating the given XPath for each target.


ApplyStylesheet

ParameterExample value
xmlTarget.
xmlValueitem[1]/text/text()
xmlStylesheetitem[2]/text/text()

This command applies the given stylesheet (as xml text) to the given value (as xml or html text.)

You can obtain the XML text from a node, as here, or from a URL, using

tb:get-url('file:path-to-xml')

The xmlStylesheetParams are parsed from the following form:

paramName=xpath;paramName=xpath;...

and the values of the XPath are passed (as strings) to the stylesheet.

This command expects to obtain a (list of) items (and/or adornments) from the stylesheet and adds them to the targetNote.

Note that the result of applying the stylesheet does not need to be a rooted xml document, but can be a series of XML fragments.

If xmlUniqueItemSignature (a XPath) is given, a signature will be computed using that XPath for the newly created node, and the node will not be created if the target node already has a subnode with the same signature.


ApplyStylesheet

ParameterExample value
xmlTarget.
xmlValuetb:get-url('xmlrpc://www.oreillynet.com/meerkat/xml-rpc/server.php;meerkat.getCategories')
xmlStylesheetitem[1]/text/text()

This is the most advanced demonstration; it allows to call an arbitrary XML-RPC method. It uses the xmlrpc URI scheme described here:

http://mah.everybody.org/docs/xmlrpc-url-scheme-rfc

The results from the calling the XML-RPC procedure will be transformed by the specified XSLT stylesheet into Tinderbox nodes, which will then be inserted under the XML-RPC call definition.


ClearProperty

ParameterExample value
xmlTargetitem
xmlName'example'

Clears the named property of the target nodes


ClearText

ParameterExample value
xmlTargetitem

Clears the text of the target nodes


CopyNote

ParameterExample value
xmlTargetitem[tb:property('Name')='Target']
xmlValue../item[tb:prototype()='test']

Move a (list of) value notes to a target Note.

Note that, as prototypes are links and not really properties, they are not maintained


CreateAlias

ParameterExample value
xmlTargetitem[tb:property('Name')='Target']
xmlValue../item[string-length(tb:property('Name'))=2]

Create aliases of each of the valueNotes under the targetNote.

This acts as a traditional Tinderbox agent.

If an alias to the same note already exists, it is not duplicated, but existing aliases are not cleared.


CreateLink

ParameterExample value
xmlTargetitem
xmlValuetb:command-note()/item[substring-after(tb:property('Name',tb:target-note()),tb:property('Name'))!='']
xmlName'-example'

create new links from each of a list of target Notes to a set of value notes.

The value notes are given by XPath, recomputed relative to each target note.

The name of the link is optional. If prefixed by a "-", the link direction will be from value to target.

Here, we are using a name prefix to determine nodes


CreateNote

ParameterExample value
xmlTarget.
xmlName'new note'

Create a new note under each target note.


CreateUrlLink

ParameterExample value
xmlTarget.
xmlValue'http://www.example.com/'
xmlName'href'

create new links from each of a list of target Notes to a URL.


DeleteNote

ParameterExample value
xmlTargetitem[tb:property('Name')='Goner']

Removes the target nodes from the document


DoOnce

ParameterExample value
xmlTarget.

Do the command(s) under this once, and deactivate self.


Eval

ParameterExample value
xmlTarget.

The Eval command will simply evaluate a XPath and do nothing with it. It is mostly useful in combination with the tb:result-of XPath extension.


ExecuteScript

ParameterExample value
xmlTarget.
  1. This node contains a python function.

def p(tbDoc,*a):

x = tbDoc.evalXPath("//item[tb:prototype() = 'XMLCommand']")

tbDoc.createAlias(tbDoc.commandNote, x)

return x


ForEach

ParameterExample value
xmlTarget.//item[attribute[@name='Alias']]

This is the most powerful command: It will execute all commands under it once for each target.

It can also act as a conditional, if the target XPath evaluates as an empty list.

At each step, the result of this note is set to be the current target note, which you can retrieve using

tb:result-of(some expression that returns the ForEach command note)


MoveNote

ParameterExample value
xmlTargetitem[tb:property('Name')='Target']
xmlValue../item[tb:prototype()='test']

Move a (list of) value notes to a target Note.


SetProperty

ParameterExample value
xmlTargetitem
xmlValuestring-length(tb:property('Name'))
xmlName'example'

Set the property 'xmlName' to the value given by applying the 'xmlValue' XPath on each of the (list of) target notes.

The value is considered to be a XPath, computed at each target note.

Note: You have to make sure the attribute name is declared as a user attribute for this document; this does not (yet) ensure user attribute declarations.


SetPrototype

ParameterExample value
xmlTargetitem
xmlName'test'

Set each target node's prototype to the given prototype. Give either the prototype's node (from the value XPath) or name.


SetText

ParameterExample value
xmlTargetitem
xmlValueconcat('Setting text to ',tb:property('Name'))

set the text of each target node to the result of evaluating the given XPath for each target.


Last modified on 03/02/06. Created by Marc-Antoine Parent with Tinderbox 3.0.4.