NAME

XML::Template::Element::Var - XML::Template plugin module for the var namespace.

SYNOPSIS

This XML::Template plugin module implements the var namespace tagset. The var namespace includes tags that handle scalar, array, nested, and XPath variables.

CONSTRUCTOR

XML::Template::Element::Var inherits its constructor method, new, from XML::Template::Element.

VAR TAGSET METHODS

set

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:

name

The name of the variable to set in XML::Template variable format.

scope

The context in which to create the new variable: global or local. The default value is local.

unset

This metho implements the unset element which unsets (deletes) a variable from the current variable context. The following attributes are used:

name

The name of the variable to unset in XML::Template variable format.

element

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:

name

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>

get

This method implements the get element which returns the value of a variable. The following attributes are used:

name

The name of the variable whose value you wish to return in XML::Template variable format.

dump

This method implements the dump element which dumps the contents of a variable using Data::Dumper. The following attributes are used:

name

The name of the variable to dump in XML::Template variable name format.

foreach

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:

src

The name of the variable whose value you wish to iterate through.

var

The name of the variable, available in the content, that contains the current array element value.

For instance,

<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>

XML::Template SUBROUTINES

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.

push

This subroutine pushes a value onto the end of the array referenced by the value. The additional parameter is the new value to add.

pop

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.

shift

This method shifts a value off the beginning of the array referenced by the value.

join

This method joins the strings in the array referenced by the value. The additional parameter specified the separator to use between the strings.

split

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.

length

This method returns the number of elements in the array referenced by value.

AUTHOR

Jonathan Waxman <jowaxman@bbl.med.upenn.edu>

COPYRIGHT

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:

Around line 214:

You forgot a '=back' before '=head2'