# perldoc > XML::LibXSLT

---
type: CommandReference
command: XML::LibXSLT
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `XML::LibXSLT->new()` — create new XSLT processor
- `$xslt->parse_stylesheet($style_doc)` — parse an XSLT stylesheet from a LibXML document
- `$stylesheet->transform($doc, %params)` — transform an XML document
- `$stylesheet->output_as_bytes($result)` — get output as bytes
- `$xslt->register_function($uri, $name, $subref)` — register XSLT extension function
- `$stylesheet->register_element($uri, $name, $subref)` — register XSLT extension element
- `$xslt->max_depth(1000)` — set maximum recursion depth

## Name

Interface to the GNOME libxslt library

## Synopsis

perl
use XML::LibXSLT;
use XML::LibXML;

my $xslt = XML::LibXSLT->new();

my $source = XML::LibXML->load_xml(location => 'foo.xml');
my $style_doc = XML::LibXML->load_xml(location=>'bar.xsl', no_cdata=>1);

my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($source);
print $stylesheet->output_as_bytes($results);
## Options

Global options (set per process, not thread-safe). Each returns previous value, call without parameter to get current.

- `$xslt->max_depth(1000)` — maximum recursion depth for a stylesheet (default 250)
- `$xslt->max_vars(100_000)` — maximum number of variables (default system-specific)
- `$xslt->debug_callback($subref)` — callback for debug messages (ignored if not set)
- `$xslt->register_function($uri, $name, $subref)` — register XSLT extension function in namespace `$uri`. Parameters: nodelist becomes `XML::LibXML::NodeList`, others plain scalars unless `$XML::LibXSLT::USE_LIBXML_DATA_TYPES` is true. Returns single value.
- `$stylesheet->register_element($uri, $name, $subref)` — register XSLT extension element. Callback receives `($_, $input_node, $stylesheet_node)`. Should return a node or undef.

## Examples

### Basic transformation with parameters

perl
my $results = $stylesheet->transform($doc, foo => "'bar'");
print $stylesheet->output_as_bytes($results);
Note: parameters must be quoted as XPath strings. Use `XML::LibXSLT::xpath_to_string()` to simplify:

perl
$stylesheet->transform($doc, XML::LibXSLT::xpath_to_string(param => "string"));
### Registering an extension function

perl
XML::LibXSLT->register_function("urn:foo", "bar",
    sub { scalar localtime });
XSLT stylesheet:

xml
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:foo="urn:foo">
  <xsl:template match="/">
    The time is: <xsl:value-of select="foo:bar()"/>
  </xsl:template>
</xsl:stylesheet>
### Registering an extension element

perl
$stylesheet->register_element("urn:foo", "hello", sub {
    my $name = $_[2]->getAttribute("name");
    return XML::LibXML::Text->new("Hello, $name!");
});
XSLT stylesheet (note `extension-element-prefixes`):

xml
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:foo="urn:foo"
  extension-element-prefixes="foo">
  <xsl:template match="/">
    <foo:hello name="bob"/>
  </xsl:template>
</xsl:stylesheet>
## See Also

- [XML::LibXML](http://localhost/phpMan.php/perldoc/XML%3A%3ALibXML/markdown) — XML parsing and document handling
- [XML::LibXSLT::Stylesheet](http://localhost/phpMan.php/perldoc/XML%3A%3ALibXSLT%3A%3AStylesheet/markdown) — stylesheet object API
- [XML::LibXSLT::Security](http://localhost/phpMan.php/perldoc/XML%3A%3ALibXSLT%3A%3ASecurity/markdown) — security callbacks (read/write file, network, etc.)
- [XML::LibXML::InputCallback](http://localhost/phpMan.php/perldoc/XML%3A%3ALibXML%3A%3AInputCallback/markdown) — input callbacks
- [XML::LibXSLT::TransformContext](http://localhost/phpMan.php/perldoc/XML%3A%3ALibXSLT%3A%3ATransformContext/markdown) — transform context object
- Report bugs at [RT CPAN](http://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-LibXSLT)