` element applies templates to selected nodes. It is used for recursive and flexible processing.
Example:
.. code-block:: xml
XSLT on the Client
-------------------
XSLT transformations can be applied directly in the browser (e.g., Chrome, Firefox) using an XML document linked to an XSL stylesheet.
Example XML linking to XSL:
.. code-block:: xml
XSLT on the Server
-------------------
Server-side XSLT transformations are done using languages like PHP, Java, .NET, or Node.js.
The server processes the XML and XSLT, then sends the transformed result (e.g., HTML) to the client.
Example (PHP):
.. code-block:: php
$xml = new DOMDocument;
$xml->load('library.xml');
$xsl = new DOMDocument;
$xsl->load('library.xsl');
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);
echo $proc->transformToXML($xml);
XSLT Edit XML
-------------
XSLT can also modify the structure of XML during transformation:
- Adding or removing elements
- Changing attribute values
- Reorganizing content
Example (adding an attribute):
.. code-block:: xml
XSLT Examples
-------------
Full Example:
Input XML:
.. code-block:: xml
Harry Potter
J.K. Rowling
XSLT:
.. code-block:: xml
Library Books
by
Result:
.. code-block:: html
Library Books
Harry Potter by J.K. Rowling