Re: Fun with XSLT
| From: | Peter Ford | Date: | Thu, 22 Oct 2009 15:44:43 +0000 |
| Subject: | Re: Fun with XSLT | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-299221@lists.php.net to get a copy of this message | ||
Matthew Croud wrote:
> Hi Guys,
>
> Well i;ve been slaving on with my PHP XML endeavors and i'm loving it,
> just finishing the meaty parts of my XSLT for dummies book too.
>
> I have a question which asks "is it possible?".
>
> Using XSLT I can collect specific parts of my XML using something sexy
> like <xsl:template match="umbungo">. Lets say however, that I need to
> use XSLT, but I would want the user to select which element they
> request. In other words, they are given a form with options and that
> form can manipulate the .XSL file.
>
> Now I know it could be done in a lengthly manner by just opening the XSL
> file and manipulating it like fopen or something like that, but is there
> a way to somehow embed the contents of the xml into the php code (like
> using <<< EOF for html), and being able to substitute the template match
> string for a variable ?
>
> Any ideas ?
>
> Thanks Gamesmaster,
> Matt
>
Despite my other post, of course you can generate the XSL on the fly:
<?php
$choice='umbongo';
$xslScript <<<EoXSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" />
<xsl:template match='/'>
<xsl:apply-templates/>
</xsl:template>
<xsl:template
match='{$choice}'><xsl:apply-templates/></xsl:template>
</xsl:stylesheet>
EoXSL
$xslt = new DOMDocument();
$xslt->loadXML($xslScript);
// ... etc...
?>
--
Peter Ford phone: 01580 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent