XML::XSLT(3pm)
π XML::XSLT β the perl module for processing XSLT π
okay bestie, sit down, hydrate, because this is the XML::XSLT manual page (yeah, the 3pm one, the User Contributed Perl Documentation one) and she is so much more than she looks. let's get into it π«Ά
β¨ NAME β¨
XML::XSLT β A perl module for processing XSLT. that's it. that's the whole name. iconic behavior honestly π
β¨ SYNOPSIS β¨
here's the vibe, no notes:
use XML::XSLT;
my $xslt = XML::XSLT->new ($xsl, warnings => 1);
$xslt->transform ($xmlfile);
print $xslt->toString;
$xslt->dispose();
like... look at her go. π
β¨ DESCRIPTION β¨
so this module implements the W3C's XSLT specification. the goal is a full implementation of the spec, but bestie... we have not yet achieved that. π however! it already works well, fr fr. see "XML::XSLT Commands" for the current status of each command, because some of these xsl commands are eating and some of them are lowkey just vibing in the "not supported yet" corner.
also important: XML::XSLT makes use of XML::DOM and LWP::Simple, while XML::DOM uses XML::Parser. therefore XML::Parser, XML::DOM and LWP::Simple have to be installed properly for XML::XSLT to run. no shortcuts, no cap. π§
πΈ Specifying Sources πΈ
the stylesheets and the documents may be passed as filenames, file handles, regular strings, string references or DOM-trees. functions that require sources (e.g. new) will accept either a named parameter or simply the argument. she's flexible like that π
either of the following are allowed:
my $xslt = XML::XSLT->new($xsl);
my $xslt = XML::XSLT->new(Source => $xsl);
in documentation, the named parameter Source is always shown, but it is never required. yes, really. it's giving optional. π
π¦ METHODS π¦
new(Source => $xml [, %args])β returns a new XSLT parser object. valid flags are:DOMparser_argsβ hashref of arguments to pass to theXML::DOM::Parserobject'sparsemethod.variablesβ hashref of variables and their values for the stylesheet.baseβ base of URL for file inclusion.debugβ turn on debugging messages.warningsβ turn on warning messages.indentβ starting amount of indention for debug messages. defaults to0.indent_incrβ amount to indent each level of debug message. defaults to1.
open_xml(Source => $xml [, %args])β gives the XSLT object new XML to process. returns anXML::DOMobject corresponding to the XML.baseβ the base URL to use for opening documents.parser_argsβ arguments to pass to the parser.
open_xsl(Source => $xml, [, %args])β gives the XSLT object a new stylesheet to use in processing XML. returns anXML::DOMobject corresponding to the stylesheet. any arguments present are passed to theXML::DOM::Parser.baseβ the base URL to use for opening documents.parser_argsβ arguments to pass to the parser.
process(%variables)β processes the previously loaded XML through the stylesheet using the variables set in the argument.transform(Source => $xml [, %args])β processes the given XML through the stylesheet. returns anXML::DOMobject corresponding to the transformed XML. any arguments present are passed to theXML::DOM::Parser.serve(Source => $xml [, %args])β processes the given XML through the stylesheet. returns a string containing the result. example:
use XML::XSLT qw(serve);
$xslt = XML::XSLT->new($xsl);
print $xslt->serve $xml;
http_headersβ if true, then prepends the appropriate HTTP headers (e.g.Content-Type,Content-Length); defaults to true.xml_declarationβ if true, then the result contains the appropriate<?xml?>header. defaults to true.xml_versionβ the version of the XML. defaults to1.0.doctypeβ the type of DOCTYPE this document is. defaults toSYSTEM.
xsl_output_methodβ get or set the<xsl:output method=attribute. valid arguments are'html','text'and'xml'. periodt. πtoStringβ returns the result of transforming the XML with the stylesheet as a string.to_domβ returns the result of transforming the XML with the stylesheet as anXML::DOMobject.media_typeβ returns the media type (aka mime type) of the object.disposeβ executes the"dispose"method on eachXML::DOMobject.
π₯ XML::XSLT Commands π₯
okay this is the part where we do the vibe check on every single xsl command. buckle up bestie, it's a long list and i'm not skipping a single one. π
xsl:apply-importsβnoβ not supported yet.xsl:apply-templatesβlimitedβ attribute'select'is supported to the same extent asxsl:value-ofsupports path selections.- not supported yet:
- attribute 'mode' - xsl:sort and xsl:with-param in content
- not supported yet:
xsl:attributeβpartiallyβ adds an attribute named to the value of the attribute'name'and as value the stringified content-template.- not supported yet:
- attribute 'namespace'
- not supported yet:
xsl:attribute-setβyesβ partially.xsl:call-templateβyesβ takes attribute'name'which selectsxsl:template's by name.- weak support:
- xsl:with-param (select attrib not supported) - not supported yet:
- xsl:sort
- weak support:
xsl:chooseβyesβ tests sequentially allxsl:whens until one succeeds or until anxsl:otherwiseis found. limited test support, seexsl:when.xsl:commentβyesβ supported. πxsl:copyβpartiallyxsl:copy-ofβlimitedβ attribute'select'functions as well as withxsl:value-of.xsl:decimal-formatβnoβ not supported yet.xsl:elementβyesxsl:fallbackβnoβ not supported yet.xsl:for-eachβlimitedβ attribute'select'functions as well as withxsl:value-of.- not supported yet:
- xsl:sort in content
- not supported yet:
xsl:ifβlimitedβ identical toxsl:when, but outsidexsl:choosecontext.xsl:importβnoβ not supported yet.xsl:includeβyesβ takes attributehref, which can be relative-local, absolute-local as well as an URL (preceded by identifierhttp:).xsl:keyβnoβ not supported yet.xsl:messageβnoβ not supported yet.xsl:namespace-aliasβnoβ not supported yet.xsl:numberβnoβ not supported yet.xsl:otherwiseβyesβ supported.xsl:outputβlimitedβ only the initialxsl:outputelement is used. the"text"output method is not supported, but shouldn't be difficult to implement. only the"doctype-public","doctype-system","omit-xml-declaration","method", and"encoding"attributes have any support.xsl:paramβexperimentalβ synonym forxsl:variable(currently). seexsl:variablefor support.xsl:preserve-spaceβnoβ not supported yet. whitespace is always preserved.xsl:processing-instructionβyesβ supported.xsl:sortβnoβ not supported yet.xsl:strip-spaceβnoβ not supported yet. no whitespace is stripped.xsl:stylesheetβlimitedβ minor namespace support: other namespace than'xsl:'for xsl-commands is allowed if xmlns-attribute is present. xmlns URL is verified. other attributes are ignored.xsl:templateβlimitedβ attribute'name'and'match'are supported to minor extend. ('name'must match exactly and'match'must match with full path or no path)- not supported yet:
- attributes 'priority' and 'mode'
- not supported yet:
xsl:textβyesβ supported.xsl:transformβlimitedβ synonym forxsl:stylesheet.xsl:value-ofβlimitedβ inserts attribute or element values. limited support:
<xsl:value-of select="."/>
<xsl:value-of select="/root-elem"/>
<xsl:value-of select="elem"/>
<xsl:value-of select="//elem"/>
<xsl:value-of select="elem[n]"/>
<xsl:value-of select="//elem[n]"/>
<xsl:value-of select="@attr"/>
<xsl:value-of select="text()"/>
<xsl:value-of select="processing-instruction()"/>
<xsl:value-of select="comment()"/>
and combinations of these.
- not supported yet:
- attribute 'disable-output-escaping'
xsl:variableβpartialor from literal text in the stylesheet.xsl:whenβlimitedβ only insidexsl:choose. limited test support:
<xsl:when test="@attr='value'"/>
<xsl:when test="elem='value'"/>
<xsl:when test="path/[@attr='value']"/>
<xsl:when test="path/[elem='value']"/>
<xsl:when test="path"/>
path is supported to the same extend as with xsl:value-of.
xsl:with-paramβexperimentalβ it is currently not functioning. (or is it?) π
π SUPPORT π
general information, bug reporting tools, the latest version, mailing lists, etc. can be found at the XML::XSLT homepage:
http://xmlxslt.sourceforge.net/
go say hi, they don't bite. π«Ά
β οΈ DEPRECATIONS β οΈ
methods and interfaces from previous versions that are not documented in this version are deprecated. each of these deprecations can still be used but will produce a warning when the deprecation is first used. you can use the old interfaces without warnings by passing "new()" the flag "use_deprecated". example:
$parser = XML::XSLT->new($xsl, "FILE",
use_deprecated => 1);
the deprecated methods will disappear by the time a 1.0 release is made. so like... don't get attached bestie. π
the deprecated methods are:
output_stringβ usetoStringinsteadresult_stringβ usetoStringinsteadoutputβ usetoStringinsteadresultβ usetoStringinsteadresult_mime_typeβ usemedia_typeinsteadoutput_mime_typeβ usemedia_typeinsteadresult_treeβ useto_dominsteadoutput_treeβ useto_dominsteadtransform_documentβ usetransforminsteadprocess_projectβ useprocessinsteadopen_projectβ use"Source"argument tonew()andtransforminstead.print_outputβ useserve()instead.
π BUGS π
yes.
(that's it. that's the entire section. the confidence. the brevity. she ate and left no crumbs. π₯)
π HISTORY π
Geert Josten and Egon Willighagen developed and maintained XML::XSLT up to version 0.22. at that point, Mark Hershberger started moving the project to Sourceforge and began working on it with Bron Gondwana. the lore is real. π
π LICENCE π
Copyright (c) 1999 Geert Josten & Egon Willighagen. All Rights Reserved. This module is free software, and may be distributed under the same terms and conditions as Perl.
π AUTHORS π
- Geert Josten
<gjosten@sci.kun.nl> - Egon Willighagen
<egonw@sci.kun.nl> - Mark A. Hershberger
<mah@everybody.org> - Bron Gondwana
<perlcode@brong.net> - Jonathan Stowe
<jns@gellyfish.com>
absolute legends, all of them. π
π¦ SEE ALSO π¦
XML::DOM, LWP::Simple, XML::Parser
and that's the whole page bestie!! πΈ this was perl v5.26.2, dated 2018-08-28 β so like, vintage but make it iconic, and honestly it still slays. go forth and transform some XML, you've got this. mwah. π
β¨π«Ά
π¦ where this page comes from
- debian bookworm: libxml-xslt-perl 0.48-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libxml-xslt-perl 0.48-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libxml-xslt-perl 0.48-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libxml-xslt-perl 0.48-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms