homepage Welcome to WebmasterWorld Guest from 54.237.249.10
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
XSL, Php5 and variables
Passing variable to XSL with Php5
eawade




msg:3948033
 1:41 am on Jul 8, 2009 (gmt 0)

Hello Everyone,

I have an issue that is driving me crazy. I have a xml document and associated stylesheet. I simply want to be able to 1: declare a top level variable 2. Pass a variable value from the URL to the stylesheet so that, for example, if [someurl.com...] - the information for the 3rd ID is displayed. Below i have sample code but i can't seem to get this to work with Php 5. Does anyone have a clue as to what is going on. After spending about a week looking through the documents for Php5 and XML, I am totally confused. Note: I am looking for the simplest / most direct solution.

Thanks,

<?php

// XML string
$xml = '<?xml version="1.0"?>
<para>
change me
</para>';

// XSL string
$xsl = '
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="ISO-8859-1" indent="no"
omit-xml-declaration="yes" media-type="text/html"/>
<xsl:param name="myvar"/>
<xsl:param name="mynode"/>
<xsl:template match="/">
My PHP variable : <xsl:value-of select="$myvar"/><br />
My node set : <xsl:value-of select="$mynode"/>
</xsl:template>
</xsl:stylesheet>';

$xh = xslt_create();

// the second parameter will be interpreted as a string
$parameters = array (
'myvar' => 'test',
'mynode' => '<foo>bar</foo>'
);

$arguments = array (
'/_xml' => $xml,
'/_xsl' => $xsl
);

echo xslt_process($xh, 'arg:/_xml', 'arg:/_xsl',NULL, $arguments, $parameters);

?>

 

httpwebwitch




msg:3948054
 2:31 am on Jul 8, 2009 (gmt 0)

seems to me like XSLT might not be the easiest tool for this.

To get some data out of "node x", you can construct an XPATH describing that node, and use some of the simpler PHP methods for grabbing the value of that node.

This will get you started:
[php.net...]

Example #1 on that page does what you're describing

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved