[PHP] Re: Fun with XSLT
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 . 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 > A bit off-topic (since XSLT is not PHP...) but here goes. First I need to clarify what you are doing - ... defines the template portion, and that is pretty immutable. At some point you must have in your XSLT something like This is the bit you can play with: so: http://www.w3.org/1999/XSL/Transform";> Essentially you need to apply the template of any element, but only those whose name matches your request. Note that doesn't work... :( So now if your PHP does something like $xslDom = new DOMDocument(); $xslDom->load('matchMe.xsl'); $xslt = new XSLTProcessor(); $xslt->importStylesheet($xslDom); $xslt->setParameter('','matchMe','umbongo'); $xmlDom = new DOMDocument(); $xmlDom->load('some_document_that_has_an_umbongo_tag.xml'); echo $xslt->transformToXML($xmlDom); you should get the results of the 'umbongo' template (only) 'f course, this is not tested, but I have used this idea in working code -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Fun with XSLT
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 . 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: http://www.w3.org/1999/XSL/Transform";> EoXSL $xslt = new DOMDocument(); $xslt->loadXML($xslScript); // ... etc... ?> -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Fun with XSLT
On 22 Oct 2009, at 16:39, Peter Ford wrote: 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 . 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 A bit off-topic (since XSLT is not PHP...) but here goes. First I need to clarify what you are doing - ... defines the template portion, and that is pretty immutable. At some point you must have in your XSLT something like This is the bit you can play with: so: http://www.w3.org/1999/XSL/Transform "> xsl:template> Essentially you need to apply the template of any element, but only those whose name matches your request. Note that doesn't work... :( So now if your PHP does something like $xslDom = new DOMDocument(); $xslDom->load('matchMe.xsl'); $xslt = new XSLTProcessor(); $xslt->importStylesheet($xslDom); $xslt->setParameter('','matchMe','umbongo'); $xmlDom = new DOMDocument(); $xmlDom->load('some_document_that_has_an_umbongo_tag.xml'); echo $xslt->transformToXML($xmlDom); you should get the results of the 'umbongo' template (only) 'f course, this is not tested, but I have used this idea in working code -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Utter brilliance, this is superb, I might drop you a mail to clarify a few things later Peter, but your reply was superb and has given me many options to try out. Thanks again! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php