Node set is the most important of the (4) primitive datatypes that an XPath expression can evaluate to. XPath's mission in life is to represent paths leading to node sets in XML documents. These are different from paths leading to files on a file system.
A node set expression is a location path that identifies a node set in an XML document. Node set expressions are part of the XSLT 1.0 specification. A node set expression is made up of 1 or more steps that are node tests:
node()
Order/text()
Customer
/Customers/Customer/Orders
This may involve explicitly stated axes:
parent::Customer
filters:
Order[@orderid >= 1000]
unions:
order|contract
wildcards:
/Customers/*/Orders/@*
and special abbreviated notations:
.
..
/Customers//Orders
|
•An absolute location path is a node set expression that DOES start with the / character. This character represents the root node, which is an imaginary node that is parent of the top-level document element of your USoft Blend script. •A relative location path is a node set expression that does NOT start with the / character. A relative location path is relative to the current node. In a Blend script, the current node is the directive currently being processed. If this is a directive with embedded XML, you can use the relative location path to point to nodes inside this embedded XML (Example 3). |
<pc:ReadXmlFile filepath="c:\temp\myxml.xml" assign:myvar="/*/Resources/RESOURCE[@type='SALES']" />
|
Here, the absolute location path /*/Resources/RESOURCE[@type='SALES'] has the root node of the "c:\temp\myxml.xml" document as its root node.
This directive first reads the external file, which is an XML document, and then assigns to the myvar variable the node set returned by applying the absolute location path to the root node of the XML document. Later in the script you can use $myvar to refer to this node set.
|
<example xmlns:pc="Processing.Command"/>
<pc:defs>
<File path="c:\temp\assets.xml" entryname="assets/assets.xml"/>
<File path="c:\temp\resources.xml" entryname="mypath/resources.xml"/>
</pc:defs>
<pc:ZipFileCreate filepath="c:\temp\mynewzip.zip" select="/*/pc:defs/File" />
</example>
|
Here, the absolute location path /*/pc:defs/File has the root node of the script itself (the parent node of the <example> document node) as its root node. The pc:ZipFileCreate directive refers back to the pc:defs section to find its input information.
|
<pc:ZipFileCreate filepath="c:\temp\mynewzip.zip" pc:return="*[contains(@path,'.xml')]">
<File path="c:\temp\assets.xml" entryname="assets/assets.xml"/>
<File path="c:\temp\resources.xml" entryname="mypath/resources.xml"/>
<File path="c:\temp\resources.txt" entryname="mypath/resources.txt"/>
</pc:ZipFileCreate>
|
Here, the relative location path *[contains(@path,'.xml')] has as context node the root node of the return value of pc:ZipFileCreate, which is the same as the embedded node set, ie., the non-visible parent node of the three <File> elements.
This example creates a new ZIP file and returns a list of all those files zipped that have the .XML extension. The first two <File> elements referring to files with an ".xml" extension refer to the content that is zipped. The last <File> element, which refers to a file with extension '.txt', is ignored.
|
<pc:JsonToXml assign:mydata="." >
<pc:ReadFile filepath="c:\temp\myfile.json"/>
</pc:JsonToXml>
|
Here, the relative location path . (ie., the full stop character in the first line) has as its context node the root node of the embedded node set, ie., the non-visible parent node of the top-level document element of the JSON file found on the file system.
This example assigns to a variable called mydata the value of the <pc:JsonToXml> element, which is itself the result of converting JSON code found in a file to XML.
The JSON code is first read, then converted to XML, and then stored in the mydata variable, ready to be referred to by $mydata.
|
See also
Guide to expressions and data types
Literal expressions
Dates
string literals
Path expressions
XML expressions
XPath expressions
Node set expressions
Booleans
Strings
Numbers
Function calls
Variable references
Implicit XPath datatype conversion
Evaluated expressions vs. literals
SQL expressions
|