XML::Template::Element::Var - XML::Template plugin module for the var namespace.
This XML::Template plugin module implements the var namespace tagset. The var namespace includes tags that handle scalar, array, nested, and XPath variables.
XML::Template::Element::Var inherits its constructor method, new, from XML::Template::Element.
new
This method implements the set element which set a variable. The value of the variable is contained in the content. The following attributes are used:
The name of the variable to set in XML::Template variable format.
The context in which to create the new variable: global or local. The default value is local.
global
local
This metho implements the unset element which unsets (deletes) a variable from the current variable context. The following attributes are used:
The name of the variable to unset in XML::Template variable format.
This method implements the element element which must be nested in the set element. It is used to set array values or nested variable values. It uses the following attributes:
If you supply the name attribute, a new nested variable is created under the parent variable with this name. Otherwise, an additional array value is appended to the parent array.
For instance,
<xml xmlns:var="http://syrme.net/xml-template/var/v1"> <var:set name="array"> <var:element>ONE</var:element> <var:element>TWO</var:element> <var:element>THREE</var:element> </var:set> <var:set name="nested1"> <var:element name="nested2"> <var:element name="nested3"> <var:element>ONE</var:element> <var:element>TWO</var:element> <var:element>THREE</var:element> </var:element> <var:element>TWO</element> </var:element> </var:set> </xml>
This method implements the get element which returns the value of a variable. The following attributes are used:
The name of the variable whose value you wish to return in XML::Template variable format.
This method implements the dump element which dumps the contents of a variable using Data::Dumper. The following attributes are used:
The name of the variable to dump in XML::Template variable name format.
XML::Template::Element::Var is a subclass of XML::Template::Element::Iterator, so it inherits the foreach method, which in conjunction with the iterator methods defined in this module, implements iteration through arrays values. Note that XPath variables may return an array of matched element through with you may iterate. The following attributes are used:
foreach
The name of the variable whose value you wish to iterate through.
The name of the variable, available in the content, that contains the current array element value.
<xml xmlns:var="syrme.net/xml-template/var/v1"> <var:foreach src="nested.array" var="el"> ${el} </var:foreach> <var:foreach src="xml[2]/employee[@type="fulltime"]/lastname/text()" var="lastname"> ${lastname} </var:foreach> </xml>
Several method exist in XML::Template::Element::Var that implement XML::Template subroutines that operate on variables. This module should be associated with them in the XML::Template configuration file. See XML::Template::Subroutine for more details.
This subroutine pushes a value onto the end of the array referenced by the value. The additional parameter is the new value to add.
This method pops a value off the end of the array referenced by the value.
This method unshifts a new value onto the beginning of the array referenced by the value. The additional parameter is the new value to add.
This method shifts a value off the beginning of the array referenced by the value.
This method joins the strings in the array referenced by the value. The additional parameter specified the separator to use between the strings.
This method splits a string into substrings and returns a reference to an array containing them. The additional parameter specified the separator to split the string on.
This method returns the number of elements in the array referenced by value.
Jonathan Waxman <jowaxman@bbl.med.upenn.edu>
Copyright (c) 2002-2003 Jonathan A. Waxman All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head2'
To install XML::Template, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::Template
CPAN shell
perl -MCPAN -e shell install XML::Template
For more information on module installation, please visit the detailed CPAN module installation guide.