Any-Renderer

 view release on metacpan or  search on metacpan

lib/Any/Renderer/XSLT.pm  view on Meta::CPAN

  TRACE ( "Any::Renderer::XSLT::_xslt_from_file - reading XSLT from disk '$filename'" );

  $XMLParser ||= new XML::LibXML ();

  my $xslt = new XML::LibXSLT ();
  my $stylesheet = $xslt->parse_stylesheet($XMLParser->parse_file ( $filename ));
  return $stylesheet;
}

sub _xslt_from_string
{
  my ( $string ) = @_;
  TRACE ( "Any::Renderer::XSLT::_xslt_from_string" );

  $XMLParser ||= new XML::LibXML ();

  my $xslt = new XML::LibXSLT ();
  my $stylesheet = $xslt->parse_stylesheet($XMLParser->parse_string( $string ));
  return $stylesheet;
}

sub TRACE {}
sub DUMP {}

1;

=head1 NAME

Any::Renderer::XSLT - render by XLST of XML element representation of data structure

=head1 SYNOPSIS

  use Any::Renderer;

  my %xml_options = ();
  my %options = (
    'XmlOptions' => \%xml_options,
    'Template'   => 'path/to/template.xslt',
  );
  my $format = "XSLT";
  my $r = new Any::Renderer ( $format, \%options );

  my $data_structure = [...]; # arbitrary structure code
  my $string = $r->render ( $data_structure );

You can get a list of all formats that this module handles using the following syntax:

  my $list_ref = Any::Renderer::XSLT::available_formats ();

Also, determine whether or not a format requires a template with requires_template:

  my $bool = Any::Renderer::XSLT::requires_template ( $format );

=head1 DESCRIPTION

Any::Renderer::XSLT renders a Perl data structure as an interstitial XML
representation (via Any::Renderer::XML) and then proceeds to apply a XSLT transformation to it to generate
the final output.

XSL Templates expressed as filenames are cached using a package-level in-memory cache with Cache::AgainstFile.  
This will stat the file to validate the cache before using the cached object, so if the template is updated,
this will be immediately picked up by all processes holding a cached copy.

=head1 FORMATS

=over 4

=item XSLT

=back

=head1 METHODS

=over 4

=item $r = new Any::Renderer::XSLT($format,\%options)

C<$format> must be C<XSLT>.
See L</OPTIONS> for a description of valid C<%options>.

=item $scalar = $r->render($data_structure)

The main method.

=item $bool = Any::Renderer::XSLT::requires_template($format)

True in this case.

=item $list_ref = Any::Renderer::XSLT::available_formats()

Just the one - C<XSLT>.

=back

=head1 OPTIONS

=over 4

=item XmlOptions

A hash reference to options passed to XML::Simple::XMLout to control the generation of the interstitial XML.
See L<XML::Simple> for a detailed description of all of the available options.

=item VariableName

Set the XML root element name in the interstitial XML. You can also achieve this by setting the
C<RootName> or C<rootname> options passed to XML::Simple in the C<XML> options
hash. This is a shortcut to make this renderer behave like some of the other
renderer backends.

=item Template (aka TemplateFilename)

Filename of XSL template.  Mandatory unless TemplateString is defined.

=item TemplateString

String containing XSL template.  Mandatory unless Template or TemplateFilename is defined.

=item NoCache

Disable in-memory caching of XSLTs loaded from the filesystem.



( run in 1.204 second using v1.01-cache-2.11-cpan-140bd7fdf52 )