Arbitrary XML files are loaded by the $xml.dom(filename) method, an instance of the DOMFileFactory class. The class of document object is determined by the dom.data.class property and defaults to a SportPage JDOMFile object.
JDOMFile provides methods to query, transform and output the XML from within a template (see Sportwire JDOMFile API Docs) and uses the TTL cache to temporarily store parsed documents.
XML is queried by retrieving the JDOM Document from the JDOMFile object and applying the standard JDOM access methods. XPath methods are on the TODO list.
To transform an XML file, the file must be first loaded by the $xml object. For example, if you're using the pathinfo to specify the XML file, you would insert the XML file specified by the path relative to dom.home with the following template code:
#set ($dom = $xml.dom( $path ))
The transform(xslfile) method creates a new JDOMFile object:
#set ($d = $dom.transform( "/path/to/transform.xsl" ))
You can then insert the result via the XML method to include the XML text inline:
$d.xml
If you want to save space, this can be collapsed into
$xml.dom( $path ).transform( "/path/to/transform.xsl" ).xml
Note | |
---|---|
Since transform returns the newly transformed document, you can chain calls, appling each XSL file to the result of the previous transform. |
As a side benefit, if you want to look at any XML file as a nicely formatted block of text, you create a webpage which simply says ...
$xml.dom( $path ).xml