From 51609351f2c4b5082b7e6f0744cd3811c325303f Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 11 Oct 2016 14:01:29 +0200 Subject: * initial template --- lib/querypath/Extension/QPXSL.php | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 lib/querypath/Extension/QPXSL.php (limited to 'lib/querypath/Extension/QPXSL.php') diff --git a/lib/querypath/Extension/QPXSL.php b/lib/querypath/Extension/QPXSL.php new file mode 100644 index 0000000..4adb317 --- /dev/null +++ b/lib/querypath/Extension/QPXSL.php @@ -0,0 +1,75 @@ + + * @license http://opensource.org/licenses/lgpl-2.1.php LGPL or MIT-like license. + * @see QueryPathExtension + * @see QueryPathExtensionRegistry::extend() + * @see QPXSL + * @see QPXML + */ + +/** + * Provide tools for running XSL Transformation (XSLT) on a document. + * + * This extension provides the {@link QPXSL::xslt()} function, which transforms + * a source XML document into another XML document according to the rules in + * an XSLT document. + * + * This QueryPath extension can be used as follows: + * + * xslt('stylesheet.xml')->writeXML(); + * ?> + * + * This will transform src.xml according to the XSLT rules in + * stylesheet.xml. The results are returned as a QueryPath object, which + * is written to XML using {@link QueryPath::writeXML()}. + * + * + * @ingroup querypath_extensions + */ +class QPXSL implements QueryPathExtension { + + protected $src = NULL; + + public function __construct(QueryPath $qp) { + $this->src = $qp; + } + + /** + * Given an XSLT stylesheet, run a transformation. + * + * This will attempt to read the provided stylesheet and then + * execute it on the current source document. + * + * @param mixed $style + * This takes a QueryPath object or any of the types that the + * {@link qp()} function can take. + * @return QueryPath + * A QueryPath object wrapping the transformed document. Note that this is a + * different document than the original. As such, it has no history. + * You cannot call {@link QueryPath::end()} to undo a transformation. (However, + * the original source document will remain unchanged.) + */ + public function xslt($style) { + if (!($style instanceof QueryPath)) { + $style = qp($style); + } + $sourceDoc = $this->src->top()->get(0)->ownerDocument; + $styleDoc = $style->get(0)->ownerDocument; + $processor = new XSLTProcessor(); + $processor->importStylesheet($styleDoc); + return qp($processor->transformToDoc($sourceDoc)); + } +} +QueryPathExtensionRegistry::extend('QPXSL'); \ No newline at end of file -- cgit v1.2.3