The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Business::Associates::XML - encapsulating XML, XSL, and XSLT operations for the Associates package

SYNOPSIS

    use Business::Associates::Data();
    use Business::Associates::XML();

    $data = Business::Associates::Data->$type ($what, $mode);
    $xml  = new Business::Associates::XML ($data) if defined $data;
    $s    = $xml->transform($ss_name, %args)      if defined $xml;
    print "\n\n$s\n";

METHODS

new($data [, %options ])

This constructor takes an Business::Associates::Data object as the required argument. The optional options hash can be used to set additional values.

xml

This is the parsed xml string. If you want to pass special arguments to the XML::LibXML library then you can do it with this argument:

  $data = Business::Associates::Data->$type ($what, $mode);
  my $xml_string = $data->xml();
  my $parser = XML::LibXML->new();
  $parser->load_ext_dtd(0); # Global setting, unfortunately :-(
  my $xml = new Business::Associates::XML(
     xml => $parser->parse_string($xml_string));
  ...

It is possibly more efficient to access this element directly after the construction to set the options on the newly constructed XML::LibXML object.

transform($stylesheet_name [, %args ] )

This method transforms the XML using the named stylesheet, parsing any additional arguments to the stylesheet transform method. Typically, these additional arguments are used to set global XSLT parameters.

  $data = Business::Associates::Data->$type ($what, $mode);
  $xml  = new Business::Associates::XML ($data);
  $s    = $xml->transform($ss_name, width => "'3'");

Note that these are named stylesheets. By default, they are found in the Base_Directory (see "Base_Directory") with the same name and the extension .xslt. To change this, either change the Base_Directory variable, or derive another class from this, overriding the get_stylesheet method.

NOTE: in the current version, if the parameter associates_id is not set in the %args hash, then the default value from Business::Associates::Data (see "VARIABLES" in Business::Associates::Data is inserted. I recommend that you do not rely on this behavior!

append($xml)

This method appends $xml (which is of type Business::Associates::XML) to the current XML object, inserting all elements below the root of $xml after the last child of the current XML.

This is used to implement searched across multiple product categories. For example

    my $mode="music dvd";
    my $xml;
    my $s = "";
    foreach my $m (split /\s+/, $mode) {
        my $data = Business::Associates::Data->$type ($what, $m);
        if (not defined $xml) {
        $xml  = new Business::Associates::XML ($data) if defined $data->xml();
        }
        else {
        my $x = new Business::Associates::XML ($data) if defined $data->xml();
        $xml->append($x)  || die "No append!";
        }
    }
    $s    = $xml->transform($ss_name, %args)  if defined $xml;
    print "\n\n$s\n";

Note that after you append then new XML document may not be in a format that is compatible with the original DTD.

VARIABLES

@Stylesheet_Path

This variable provides an array of directories to search for the named style sheets. The default value is

    ("/var/www/stylesheets", @INC)

Note that the directories specified and any sub-directories called Business/Associates are searched.

$Base_Directory [Default: "/var/www/stylesheets/"]

DEPRECIATED: Use @Stylesheet_Path instead. This is now an alias for $Stylesheet_Path[0].

This is the base directory for all stylesheets. You will probably want to override this:

    use Business::Associates::XML();
    $Associates::XML::Base_Directory = "/my/path";
$Always_Load [Default: 0]

This is a little hack for developers. If this value is set to 1 then no styelsheets are chached in memory by the default get_stylesheet funtion. Instead they are read from the file every time.

DESCRIPTION

This module provides a simple interface to the XML libraries. The main reason for havinf this module at all, is to allow us to switch to another XML implenetation in the future, should we want to do this.

BUGS

Please report bugs to the author.

SEE ALSO

See also XML::LibXSLT, XML::LibXML, libxml(4), and File::Spec.

AUTHOR

This package was written by Allan Engelhardt <allane@cybaea.com>

COPYING

Copyright (c) 2002 Allan Engelhardt <allane@cybaea.com>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA