|
Note: SQL databases are also supported - xml is being used for the example because it is easier to show an xml file on the web.
Now you need to take your sample document and put in the places where you want data substituted as the report is generated. Windward Reports uses a language called XPath to identify elements in the xml file. It is much like a file directory (folder) system. "/order/customer/name" will return "John Smith".
The tag <wr:out …/> function is to be replaced with the text for that element in the xml file. So the final form will have "Name Acme Industries". This is similar to a Find & Replace in Word.
<wr:forEach select="/order/item"> … </wr:forEach> each row created by the forEach tag will be for a different /order/item selection of xml nodes.
<wr:out select="./description"/> Notice how the select starts with a ./ instead of a / - this means the tag is relative to the node in the select in the forEach tag.
The forEach and query tags reference nodes. And the other tags operate either off the root node of the xml (the out tags in red) or from the nodes selected by the forEach or query tags.
XPath
XPath is an open standard of identifying an element in an xml document. It is moderately complex and very powerful. It is used by xslt and xpointer to identify nodes in a xml document. If you are not familiar with xpath, click here for a short on-line tutorial.
Or here are the few constructs used in our example:
- /order/customer/company - get the node, from the root, company which is a subnode of customer which is a subnode of order. And order is the root element of the xml document.
- /order/customer/address/@city - get the city attribute from the element address.
- ./quantity - relative node - get the quantity element, which is a subnode of the node presently on (this only makes sense inside a while).
<wr:out select="xpath"/>
This command will be replaced by the text for the xpath element. If the element does not exist, it will be replaced with nothing. If the element has sub-nodes, it will be replaced with the text from all of the sub-nodes.
Example: <wr:out select="./quantity"/>
<wr:forEach select="xpath">...</wr:forEach>
This command will iterate through all of the nodes that match the xpath. Once for each matching node, it will duplicate all of the template document in the output report. This becomes useful when you have <=:xpath> statements inside the while that use relative xpath statements to insert data from the node the while statement is presently on.
While statements can be nested and the xpath statement can use "././quantity" to access one loop out.
<wr:if select="xpath">...</wr:if>
This command will only include the part of the template document between the if and the end if this node exists in the xml file. The text for the element can be null, the element must just exist.
This command can also use be written as <wr:if select="xpath">...<wr:else/>...</wr:if> and in this case it will include either the if or else part depending on the existence of the xpath node.
Example: <wr:if select="/order/customer/address/@city='Boulder'"> ... </wr:if>
|