1 | <?php |
||
2 | /** @file |
||
3 | * Provide QueryPath with XSLT support using the PHP libxslt module. |
||
4 | * |
||
5 | * This is called 'QPXSL' instead of 'QPXSLT' in accordance with the name |
||
6 | * of the PHP extension that provides libxslt support. |
||
7 | * |
||
8 | * You must have PHP XSL support for this to function. |
||
9 | * |
||
10 | * @author M Butcher <[email protected]> |
||
11 | * @license MIT |
||
12 | * @see QueryPath::Extension |
||
13 | * @see QueryPath::ExtensionRegistry::extend() |
||
14 | * @see QPXSL |
||
15 | * @see QPXML |
||
16 | */ |
||
17 | |||
18 | namespace QueryPath\Extension; |
||
19 | |||
20 | use QueryPath\QueryPath; |
||
21 | |||
22 | /** |
||
23 | * Provide tools for running XSL Transformation (XSLT) on a document. |
||
24 | * |
||
25 | * This extension provides the {@link QPXSL::xslt()} function, which transforms |
||
26 | * a source XML document into another XML document according to the rules in |
||
27 | * an XSLT document. |
||
28 | * |
||
29 | * This QueryPath extension can be used as follows: |
||
30 | * <code> |
||
31 | * <?php |
||
32 | * require 'QueryPath/QueryPath.php'; |
||
33 | * require 'QueryPath/Extension/QPXSL.php'; |
||
34 | * |
||
35 | * qp('src.xml')->xslt('stylesheet.xml')->writeXML(); |
||
36 | * ?> |
||
37 | * |
||
38 | * This will transform src.xml according to the XSLT rules in |
||
39 | * stylesheet.xml. The results are returned as a QueryPath object, which |
||
40 | * is written to XML using {@link QueryPath::writeXML()}. |
||
41 | * </code> |
||
42 | * |
||
43 | * @ingroup querypath_extensions |
||
44 | */ |
||
45 | class QPXSL implements \QueryPath\Extension |
||
46 | { |
||
47 | |||
48 | protected $src; |
||
49 | |||
50 | public function __construct(\QueryPath\Query $qp) |
||
51 | { |
||
52 | $this->src = $qp; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Given an XSLT stylesheet, run a transformation. |
||
57 | * |
||
58 | * This will attempt to read the provided stylesheet and then |
||
59 | * execute it on the current source document. |
||
60 | * |
||
61 | * @param mixed $style |
||
62 | * This takes a QueryPath object or <em>any</em> of the types that the |
||
63 | * {@link qp()} function can take. |
||
64 | * @return QueryPath |
||
65 | * A QueryPath object wrapping the transformed document. Note that this is a |
||
66 | * <i>different</em> document than the original. As such, it has no history. |
||
67 | * You cannot call {@link QueryPath::end()} to undo a transformation. (However, |
||
68 | * the original source document will remain unchanged.) |
||
69 | */ |
||
70 | public function xslt($style) |
||
71 | { |
||
72 | if (!($style instanceof QueryPath)) { |
||
73 | $style = QueryPath::with($style); |
||
74 | } |
||
75 | $sourceDoc = $this->src->top()->get(0)->ownerDocument; |
||
76 | $styleDoc = $style->get(0)->ownerDocument; |
||
0 ignored issues
–
show
|
|||
77 | $processor = new \XSLTProcessor(); |
||
78 | $processor->importStylesheet($styleDoc); |
||
79 | |||
80 | return QueryPath::with($processor->transformToDoc($sourceDoc)); |
||
81 | } |
||
82 | } |
||
83 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.