{
    "mode": "perldoc",
    "parameter": "XML::LibXSLT",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ALibXSLT/json",
    "generated": "2026-06-11T00:23:42Z",
    "synopsis": "use XML::LibXSLT;\nuse XML::LibXML;\nmy $xslt = XML::LibXSLT->new();\nmy $source = XML::LibXML->loadxml(location => 'foo.xml');\nmy $styledoc = XML::LibXML->loadxml(location=>'bar.xsl', nocdata=>1);\nmy $stylesheet = $xslt->parsestylesheet($styledoc);\nmy $results = $stylesheet->transform($source);\nprint $stylesheet->outputasbytes($results);",
    "sections": {
        "NAME": {
            "content": "XML::LibXSLT - Interface to the GNOME libxslt library\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use XML::LibXSLT;\nuse XML::LibXML;\n\nmy $xslt = XML::LibXSLT->new();\n\nmy $source = XML::LibXML->loadxml(location => 'foo.xml');\nmy $styledoc = XML::LibXML->loadxml(location=>'bar.xsl', nocdata=>1);\n\nmy $stylesheet = $xslt->parsestylesheet($styledoc);\n\nmy $results = $stylesheet->transform($source);\n\nprint $stylesheet->outputasbytes($results);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module is an interface to the GNOME project's libxslt. This is an extremely good XSLT\nengine, highly compliant and also very fast. I have tests showing this to be more than twice as\nfast as Sablotron.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "XML::LibXSLT has some global options. Note that these are probably not thread or even fork safe\n- so only set them once per process. Each one of these options can be called either as class\nmethods, or as instance methods. However either way you call them, it still sets global options.\n\nEach of the option methods returns its previous value, and can be called without a parameter to\nretrieve the current value.\n\nmaxdepth\nXML::LibXSLT->maxdepth(1000);\n\nThis option sets the maximum recursion depth for a stylesheet. See the very end of section\n5.4 of the XSLT specification for more details on recursion and detecting it. If your\nstylesheet or XML file requires seriously deep recursion, this is the way to set it. Default\nvalue is 250.\n\nmaxvars\nXML::LibXSLT->maxvars(100000);\n\nThis option sets the maximum number of variables for a stylesheet. If your stylesheet or XML\nfile requires many variables, this is the way to increase their limit. Default value is\nsystem-specific and may vary.\n\ndebugcallback\nXML::LibXSLT->debugcallback($subref);\n\nSets a callback to be used for debug messages. If you don't set this, debug messages will be\nignored.\n\nregisterfunction\nXML::LibXSLT->registerfunction($uri, $name, $subref);\n$stylesheet->registerfunction($uri, $name, $subref);\n\nRegisters an XSLT extension function mapped to the given URI. For example:\n\nXML::LibXSLT->registerfunction(\"urn:foo\", \"bar\",\nsub { scalar localtime });\n\nWill register a \"bar\" function in the \"urn:foo\" namespace (which you have to define in your\nXSLT using \"xmlns:...\") that will return the current date and time as a string:\n\n<xsl:stylesheet version=\"1.0\"\nxmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\nxmlns:foo=\"urn:foo\">\n<xsl:template match=\"/\">\nThe time is: <xsl:value-of select=\"foo:bar()\"/>\n</xsl:template>\n</xsl:stylesheet>\n\nParameters can be in whatever format you like. If you pass in a nodelist it will be a\nXML::LibXML::NodeList object in your perl code, but ordinary values (strings, numbers and\nbooleans) will be ordinary perl scalars. If you wish them to be \"XML::LibXML::Literal\",\n\"XML::LibXML::Number\" and \"XML::LibXML::Number\" values respectively then set the variable\n$XML::LibXSLT::USELIBXMLDATATYPES to a true value. Return values can be a nodelist or a\nplain value - the code will just do the right thing. But only a single return value is\nsupported (a list is not converted to a nodelist).\n\nregisterelement\n$stylesheet->registerelement($uri, $name, $subref)\n\nRegisters an XSLT extension element $name mapped to the given URI. For example:\n\n$stylesheet->registerelement(\"urn:foo\", \"hello\", sub {\nmy $name = $[2]->getAttribute( \"name\" );\nreturn XML::LibXML::Text->new( \"Hello, $name!\" );\n});\n\nWill register a \"hello\" element in the \"urn:foo\" namespace that returns a \"Hello, X!\" text\nnode. You must define this namespace in your XSLT and include its prefix in the\n\"extension-element-prefixes\" list:\n\n<xsl:stylesheet version=\"1.0\"\nxmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\nxmlns:foo=\"urn:foo\"\nextension-element-prefixes=\"foo\">\n<xsl:template match=\"/\">\n<foo:hello name=\"bob\"/>\n</xsl:template>\n</xsl:stylesheet>\n\nThe callback is passed the input document node as $[1] and the stylesheet node as $[2].\n$[0] is reserved for future use.\n",
            "subsections": []
        },
        "API": {
            "content": "The following methods are available on the new XML::LibXSLT object:\n",
            "subsections": [
                {
                    "name": "parse_stylesheet",
                    "content": "$stylesheetdoc here is an XML::LibXML::Document object (see XML::LibXML) representing an\nXSLT file. This method will return a XML::LibXSLT::Stylesheet object, or undef on failure.\nIf the XSLT is invalid, an exception will be thrown, so wrap the call to parsestylesheet in\nan eval{} block to trap this.\n\nIMPORTANT: $stylesheetdoc should not contain CDATA sections, otherwise libxslt may\nmisbehave. The best way to assure this is to load the stylesheet with nocdata flag, e.g.\n\nmy $stylesheetdoc = XML::LibXML->loadxml(location=>\"some.xsl\", nocdata=>1);\n"
                },
                {
                    "name": "parse_stylesheet_file",
                    "content": "Exactly the same as the above, but parses the given filename directly.\n"
                }
            ]
        },
        "Input Callbacks": {
            "content": "To define XML::LibXSLT or XML::LibXSLT::Stylesheet specific input callbacks, reuse the\nXML::LibXML input callback API as described in XML::LibXML::InputCallback(3).\n",
            "subsections": [
                {
                    "name": "input_callbacks",
                    "content": "Enable the callbacks in $icb only for this XML::LibXSLT object. $icb should be a\n\"XML::LibXML::InputCallback\" object. This will call \"initcallbacks\" and \"cleanupcallbacks\"\nautomatically during parsing or transformation.\n"
                }
            ]
        },
        "Security Callbacks": {
            "content": "To create security preferences for the transformation see XML::LibXSLT::Security. Once the\nsecurity preferences have been defined you can apply them to an XML::LibXSLT or\nXML::LibXSLT::Stylesheet instance using the \"securitycallbacks()\" method.\n\nXML::LibXSLT::Stylesheet\nThe main API is on the stylesheet, though it is fairly minimal.\n\nOne of the main advantages of XML::LibXSLT is that you have a generic stylesheet object which\nyou call the transform() method passing in a document to transform. This allows you to have\nmultiple transformations happen with one stylesheet without requiring a reparse.\n",
            "subsections": [
                {
                    "name": "transform",
                    "content": "my $results = $stylesheet->transform($doc, foo => \"'bar'\");\nprint $stylesheet->outputasbytes($results);\n\nTransforms the passed in XML::LibXML::Document object, and returns a new\nXML::LibXML::Document. Extra hash entries are used as parameters. Be sure to keep in mind\nthe caveat with regard to quotes explained in the section on \"Parameters\" below.\n"
                },
                {
                    "name": "transform_file",
                    "content": "my $results = $stylesheet->transformfile($filename, bar => \"'baz'\");\n\nNote the string parameter caveat, detailed in the section on \"Parameters\" below.\n"
                },
                {
                    "name": "output_as_bytes",
                    "content": "Returns a scalar that is the XSLT rendering of the XML::LibXML::Document object using the\ndesired output format (specified in the xsl:output tag in the stylesheet). Note that you can\nalso call $result->toString, but that will *always* output the document in XML format which\nmay not be what you asked for in the xsl:output tag. The scalar is a byte string encoded in\nthe output encoding specified in the stylesheet.\n"
                },
                {
                    "name": "output_as_chars",
                    "content": "Like \"outputasbytes(result)\", but always return the output as (UTF-8 encoded) string of\ncharacters.\n"
                },
                {
                    "name": "output_string",
                    "content": "DEPRECATED: This method is something between \"outputasbytes(result)\" and\n\"outputasbytes(result)\": The scalar returned by this function appears to Perl as\ncharacters (UTF8 flag is on) if the output encoding specified in the XSLT stylesheet was\nUTF-8 and as bytes if no output encoding was specified or if the output encoding was other\nthan UTF-8. Since the behavior of this function depends on the particular stylesheet, it is\ndeprecated in favor of \"outputasbytes(result)\" and \"outputaschars(result)\".\n"
                },
                {
                    "name": "output_fh",
                    "content": "Outputs the result to the filehandle given in $fh.\n"
                },
                {
                    "name": "output_file",
                    "content": "Outputs the result to the file named in $filename.\n"
                },
                {
                    "name": "output_encoding",
                    "content": "Returns the output encoding of the results. Defaults to \"UTF-8\".\n"
                },
                {
                    "name": "output_method",
                    "content": "Returns the value of the \"method\" attribute from \"xsl:output\" (usually \"xml\", \"html\" or\n\"text\"). If this attribute is unspecified, the default value is initially \"xml\". If the\ntransform method is used to produce an HTML document, as per the XSLT spec\n<http://www.w3.org/TR/xslt#output>, the default value will change to \"html\". To override\nthis behavior completely, supply an \"xsl:output\" element in the stylesheet source document.\n"
                },
                {
                    "name": "media_type",
                    "content": "Returns the value of the \"media-type\" attribute from \"xsl:output\". If this attribute is\nunspecified, the default media type is initially \"text/xml\". This default changes to\n\"text/html\" under the same conditions as outputmethod.\n"
                },
                {
                    "name": "input_callbacks",
                    "content": "Enable the callbacks in $icb only for this stylesheet. $icb should be a\n\"XML::LibXML::InputCallback\" object. This will call \"initcallbacks\" and \"cleanupcallbacks\"\nautomatically during transformation.\n"
                }
            ]
        },
        "Parameters": {
            "content": "LibXSLT expects parameters in XPath format. That is, if you wish to pass a string to the XSLT\nengine, you actually have to pass it as a quoted string:\n\n$stylesheet->transform($doc, param => \"'string'\");\n\nNote the quotes within quotes there!\n\nObviously this isn't much fun, so you can make it easy on yourself:\n\n$stylesheet->transform($doc, XML::LibXSLT::xpathtostring(\nparam => \"string\"\n));\n\nThe utility function does the right thing with respect to strings in XPath, including when you\nhave quotes already embedded within your string.\n\nXML::LibXSLT::Security\nProvides an interface to the libxslt security framework by allowing callbacks to be defined that\ncan restrict access to various resources (files or URLs) during a transformation.\n\nThe libxslt security framework allows callbacks to be defined for certain actions that a\nstylesheet may attempt during a transformation. It may be desirable to restrict some of these\nactions (for example, writing a new file using exsl:document). The actions that may be\nrestricted are:\n\nreadfile\nCalled when the stylesheet attempts to open a local file (ie: when using the document()\nfunction).\n\nwritefile\nCalled when an attempt is made to write a local file (ie: when using the exsl:document\nelement).\n\ncreatedir\nCalled when a directory needs to be created in order to write a file.\n\nNOTE: By default, createdir is not allowed. To enable it a callback must be registered.\n\nreadnet\nCalled when the stylesheet attempts to read from the network.\n\nwritenet\nCalled when the stylesheet attempts to write to the network.\n",
            "subsections": [
                {
                    "name": "Using XML::LibXSLT::Security",
                    "content": "The interface for this module is similar to XML::LibXML::InputCallback. After creating a new\ninstance you may register callbacks for each of the security options listed above. Then you\napply the security preferences to the XML::LibXSLT or XML::LibXSLT::Stylesheet object using\n\"securitycallbacks()\".\n\nmy $security = XML::LibXSLT::Security->new();\n$security->registercallback( readfile  => $readcb );\n$security->registercallback( writefile => $writecb );\n$security->registercallback( createdir => $createcb );\n$security->registercallback( readnet   => $readnetcb );\n$security->registercallback( writenet  => $writenetcb );\n\n$xslt->securitycallbacks( $security );"
                },
                {
                    "name": "-OR-",
                    "content": "$stylesheet->securitycallbacks( $security );\n\nThe registered callback functions are called when access to a resource is requested. If the\naccess should be allowed the callback should return 1, if not it should return 0. The callback\nfunctions should accept the following arguments:\n\n$tctxt\nThis is the transform context (XML::LibXSLT::TransformContext). You can use this to get the\ncurrent XML::LibXSLT::Stylesheet object by calling \"stylesheet()\".\n\nmy $stylesheet = $tctxt->stylesheet();\n\nThe stylesheet object can then be used to share contextual information between different\ncalls to the security callbacks.\n\n$value\nThis is the name of the resource (file or URI) that has been requested.\n\nIf a particular option (except for \"createdir\") doesn't have a registered callback, then the\nstylesheet will have full access for that action.\n"
                },
                {
                    "name": "Interface",
                    "content": ""
                },
                {
                    "name": "new",
                    "content": "Creates a new XML::LibXSLT::Security object.\n"
                },
                {
                    "name": "register_callback",
                    "content": "Registers a callback function for the given security option (listed above).\n"
                },
                {
                    "name": "unregister_callback",
                    "content": "Removes the callback for the given option. This has the effect of allowing all access for\nthe given option (except for \"createdir\").\n"
                }
            ]
        },
        "BENCHMARK": {
            "content": "Included in the distribution is a simple benchmark script, which has two drivers - one for\nLibXSLT and one for Sablotron. The benchmark requires the testcases files from the XSLTMark\ndistribution which you can find at http://www.datapower.com/XSLTMark/\n\nPut the testcases directory in the directory created by this distribution, and then run:\n\nperl benchmark.pl -h\n\nto get a list of options.\n\nThe benchmark requires XML::XPath at the moment, but I hope to factor that out of the equation\nfairly soon. It also requires Time::HiRes, which I could be persuaded to factor out, replacing\nit with Benchmark.pm, but I haven't done so yet.\n\nI would love to get drivers for XML::XSLT and XML::Transformiix, if you would like to contribute\nthem. Also if you get this running on Win32, I'd love to get a driver for MSXSLT via OLE, to see\nwhat we can do against those Redmond boys!\n",
            "subsections": []
        },
        "LIBRARY VERSIONS": {
            "content": "For debugging purposes, XML::LibXSLT provides version information about the libxslt C library\n(but do not confuse it with the version number of XML::LibXSLT module itself, i.e. with\n$XML::LibXSLT::VERSION). XML::LibXSLT issues a warning if the runtime version of the library is\nless then the compile-time version.\n\nXML::LibXSLT::LIBXSLTVERSION()\nReturns version number of libxslt library which was used to compile XML::LibXSLT as an\ninteger. For example, for libxslt-1.1.18, it will return 10118.\n\nXML::LibXSLT::LIBXSLTDOTTEDVERSION()\nReturns version number of libxslt library which was used to compile XML::LibXSLT as a\nstring, e.g. \"1.1.18\".\n\nXML::LibXSLT::LIBXSLTRUNTIMEVERSION()\nReturns version number of libxslt library to which XML::LibXSLT is linked at runtime (either\ndynamically or statically). For example, for example, for libxslt.so.1.1.18, it will return\n10118.\n\nXML::LibXSLT::HAVEEXLT()\nReturns 1 if the module was compiled with libexslt, 0 otherwise.\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This is free software, you may use it and distribute it under the same terms as Perl itself.\n\nCopyright 2001-2009, AxKit.com Ltd.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Matt Sergeant, matt@sergeant.org\n\nSecurity callbacks implementation contributed by Shane Corgatelli.\n",
            "subsections": []
        },
        "MAINTAINER": {
            "content": "Petr Pajas , pajas@matfyz.org\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Please report bugs via\n\nhttp://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-LibXSLT\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "XML::LibXML\n",
            "subsections": []
        }
    },
    "summary": "XML::LibXSLT - Interface to the GNOME libxslt library",
    "flags": [],
    "examples": [],
    "see_also": []
}