The XSLT component can be used to transform an XML document into something else based on XSLT templates.
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Xslt\Processor;
use VeeWee\Xml\Xslt\Configurator;
$processor = Processor::fromTemplateDocument(
Document::fromXmlFile('xml-to-yaml-converter.xslt'),
Configurator\all_functions(),
Configurator\parameters('', [
'name' => 'Jos',
])
);
$doc = Document::fromXmlFile('data.xml');
echo $processor->transformDocumentToString($doc);
It consists out of following components:
- Configurators: Specify how you want to process your XSLT templates.
- Loaders: Determine where the load the XSLT template from.
- Transformers: Specify what you want to transform to which kind of output.
Specify how you want to process your XSLT templates.
Registers all known PHP functions to the XSLTProcessor object, allowing you to use php:function('ucfirst',string(uid))
inside your XSLT Template.
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Xslt\Processor;
use function VeeWee\Xml\Xslt\Configurator\all_functions;
$processor = Processor::fromTemplateDocument(
Document::fromXmlFile('xml-to-yaml-converter.xslt'),
all_functions()
);
Registers specific PHP functions to the XSLTProcessor object, allowing you to use php:function('ucfirst',string(uid))
inside your XSLT Template.
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Xslt\Processor;
use function VeeWee\Xml\Xslt\Configurator\functions;
$processor = Processor::fromTemplateDocument(
Document::fromXmlFile('xml-to-yaml-converter.xslt'),
functions(['ucfirst'])
);
The loader configurator takes a loader to specify the source of the XSLT Template.
use VeeWee\Xml\Xslt\Processor;
use function VeeWee\Xml\Xslt\Configurator\loader;
use function VeeWee\Xml\Xslt\Loader\from_template_document;
$processor = Processor::configure(
loader(from_template_document($template))
);
Registers a map of key/value parameters to the XSLTProcessor which can be used inside your template.
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Xslt\Processor;
use function VeeWee\Xml\Xslt\Configurator\parameters;
$processor = Processor::fromTemplateDocument(
Document::fromXmlFile('xml-to-yaml-converter.xslt'),
parameters('namespace', [
'name' => 'Jos'
])
);
Specify a file in which you want to profile the XSLT processor.
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Xslt\Processor;
use function VeeWee\Xml\Xslt\Configurator\profiler;
$processor = Processor::fromTemplateDocument(
Document::fromXmlFile('xml-to-yaml-converter.xslt'),
profiler('profiler-info.txt')
);
Specify which security preferences you want to use inside the XSLT processor.
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Xslt\Processor;
use function VeeWee\Xml\Xslt\Configurator\security_preferences;
$processor = Processor::fromTemplateDocument(
Document::fromXmlFile('xml-to-yaml-converter.xslt'),
security_preferences( XSL_SECPREF_DEFAULT )
);
Determine where the load the XSLT template from.
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Xslt\Processor;
$template = Document::fromXmlFile('xml-to-yaml-converter.xslt');
$processor = Processor::fromTemplateDocument($template, ...$configurators);
Specify what you want to transform to which kind of output.
Transforms the input Document
based on the selected XSLT template into a string.
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Xslt\Processor;
$template = Document::fromXmlFile('xml-to-yaml-converter.xslt');
$document = Document::fromXmlFile('data.xml');
$processor = Processor::fromTemplateDocument($template);
$text = $processor->transformDocumentToString($document);