NAME

XML::GrammarBase::Role::XSLT - a parameterized role for XSLT conversions.

VERSION

version 0.2.10

SYNOPSIS

package XML::Grammar::MyGrammar::ToOtherStuff;

use MooX 'late';

use XML::GrammarBase::Role::RelaxNG;
use XML::GrammarBase::Role::XSLT;

with ('XML::GrammarBase::Role::RelaxNG');
with XSLT(output_format => 'html');
with XSLT(output_format => 'docbook');

has '+module_base' => (default => 'XML-Grammar-MyGrammar');
has '+rng_schema_basename' => (default => 'my-grammar.rng');

has '+to_html_xslt_transform_basename' => (default => 'mygrammar-xml-to-html.xslt');
has '+to_docbook_xslt_transform_basename' => (default => 'mygrammar-xml-to-docbook.xslt');

package main;

my $xslt = XML::Grammar::MyGrammar::ToOtherStuff->new(
    data_dir => "/path/to/data-dir",
);

# Throws an exception on failure.
my $as_html = $xslt->perform_xslt_translation(
    {
        output_format => 'html'
        source => {file => $input_filename, },
        output => "string",
    }
);

PARAMATERS

output_format

A Perl identifier string identifying the format.

SLOTS

module_base

The basename of the module - used for dist dir.

data_dir

The data directory where the XML assets can be found (the RELAX NG schema, etc.)

rng_schema_basename

The Relax NG Schema basename.

to_${output_format}_xslt_transform_basename

The basename of the primary XSLT transform file. Should be overrided in the constructor or using has '+to_html'. For example:

has '+to_html_xslt_transform_basename' => (default => 'fiction-xml-to-html.xslt');

METHODS

$self->rng_validate_dom($source_dom)

Validates the DOM ( $source_dom ) using the RELAX-NG schema.

$self->rng_validate_file($file_path)

Validates the file in $file_path using the RELAX-NG schema.

$self->rng_validate_string($xml_string)

Validates the XML in the $xml_string using the RELAX-NG schema.

$converter->perform_xslt_translation

  • my $final_source = $converter->perform_xslt_translation({output_format => $format, source => {file => $filename}, output => "string" })

  • my $final_source = $converter->perform_xslt_translation({output_format => $format, source => {string_ref => \$buffer}, output => "string" })

  • my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {file => $filename}, output => "dom" })

  • my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {dom => $libxml_dom}, output => "dom" })

  • my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {dom => $libxml_dom}, output => {file => $path_to_file,}, })

  • my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {dom => $libxml_dom}, output => {fh => $filehandle,}, })

This method does the actual conversion with the output format of $format. The 'source' argument points to a hash-ref with keys and values for the source. If 'file' is specified there it points to the filename to translate (currently the only available source). If 'string_ref' is specified it points to a reference to a string, with the contents of the source XML. If 'dom' is specified then it points to an XML DOM as parsed or constructed by XML::LibXML.

The 'output' key specifies the return value. A value of 'string' returns the XML as a string, and a value of 'dom' returns the XML as an XML::LibXML DOM object. If it is a hash ref then it specifies a 'file' or a 'fh' with a filepath or filehandle respectively.

An optional 'encoding' parameter determines if one should output the string as 'utf8' (the deafult - using XML::LibXSLT's output_as_chars()) or as 'bytes' - using its output_as_bytes() .

An optional 'xslt_params' parmater allows one to specify a hash of XSLT parameters.

BUILD

Moo constructor. For internal use.

make_variant

Package::Variant constructor. For internal use.

AUTHOR

Shlomi Fish, <shlomif at cpan.org>

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2009 Shlomi Fish.

This program is distributed under the MIT (X11) License: http://www.opensource.org/licenses/mit-license.php

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

SUPPORT

Websites

The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.

Bugs / Feature Requests

Please report any bugs or feature requests by email to bug-xml-grammarbase at rt.cpan.org, or through the web interface at https://rt.cpan.org/Public/Bug/Report.html?Queue=XML-GrammarBase. You will be automatically notified of any progress on the request by the system.

Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)

https://github.com/shlomif/perl-XML-GrammarBase

git clone git://github.com/shlomif/perl-XML-GrammarBase.git

AUTHOR

Shlomi Fish <shlomif@cpan.org>

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/shlomif/perl-XML-GrammarBase/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

COPYRIGHT AND LICENSE

This software is Copyright (c) 2018 by Shlomi Fish.

This is free software, licensed under:

The MIT (X11) License