|
The
basic manipulation in xCommerce is the Map Action which allows you to map nodes
(Elements, Attributes, etc.) from one XML document into nodes of another XML
document. The default mechanism for
specifying the Source and Target of the Map action is an XPath Location path
expressed in a fashion similar to directory hierarchies under DOS (e.g.
ROOT/CHILD/CHILD). There are two
critical concepts to understand with XPath in xCommerce.
The first is that an XPath expression always returns a list of nodes
matching the XPath pattern in the form of a NodeList object.
Second, the default behavior for a Map action is to process only the
first Node in the list (processing the entire list is handled explicitly by the
Repeat for Element action).
On
the surface it appears XPath will run out of gas rather quickly, especially if
one wants to do more than just map a single element or attribute. However, when the Map action is combined with the Repeat for
Element and Repeat for Group actions, XPath proves to very powerful indeed,
especially in specifying a NodeList within a document and across multiple
documents. For instance, if your
component has two Input documents, each containing multiple ADDRESS elements at different locations within their respective
hierarchies. XPath provides
flexible wildcard expressions to return a NodeList containing ALL the ADDRESSes.
The example below is a powerful demonstration of this with a Repeat for
Element loop that collects all the ADDRESSes in a NodeList and processes each
one with a Map action inside the loop transferring each ADDRESS to the Output
document.

Another
example is the XPath String function: translate().
This XPath function allows you to make character substitutions.
In the following example, an element using dashes as delimiters in the
phone number, is mapped with the translate() function replacing the dashes with
a period (American format 212-123-1234 to European style 212.123.1234).
A
sample project that you can download is available (http://ftp1.novell.com/pub/xcommerce/XPathFeatures.zip)
that makes exploring the
following features of XPath time well spent, as it will allow you to use
Designer's GUI
to its fullest and speed up your project development time.
Location
Path operators:
selector
brackets ( [ ] ) = specify a position in the NodeList, slash ( / ) = childnode,
double slash ( // ) = any matching node, asterisk ( * ) = positional any
matching node, vertical bar ( | ) = union
NodeSet
Functions:
count(),
last(), position(), name(), ID(), local-name(), namespace-uri()
String
Functions:
concat(),
string(), starts-with(), contains(), substring-before(), substring-after(),
substring(), string-length(), normalize-space(), translate()
Boolean
Functions:
boolean(), not(),
true(), false(), lang()
Number
Functions:
number(),
sum(), floor(), ceiling(), round()
Advantages
XPath
expressions can be automatically generated by the XPath expression builder.
Uses
a familiar syntax (directory structure slashes) for expressing locations in an
XML document hierarchy.
Good
document node selection capability across multiple documents.
Contains
some easily used and very handy functions (NodeSets, String, Boolean, and
Number).
Usable
from the Decision, Function, Log, Map, Repeat for Element, Send Mail, Process
XSL, Raise Error, Repeat for Group, Repeat While, and XML Interchange actions.
Disadvantages
Limited
set of built in functions.
Lacks
programmability.
Restricted to manipulating documents at relatively large
levels of granularity.
|