473,327 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

configuration of xsl file

hello can i put in an xsl file variables from php???
well i have 15 xsl files which have many "<a href.........." with the
url of the project. so if i want to make my project portable i must
have a config file in php probably and there put the full url of my
project and not edit every time all the 15 xsl files....
Jul 20 '05 #1
6 1651
ts*****@hotmail.com (tsirman) writes:
hello can i put in an xsl file variables from php???
well i have 15 xsl files which have many "<a href.........." with the
url of the project. so if i want to make my project portable i must
have a config file in php probably and there put the full url of my
project and not edit every time all the 15 xsl files....


Use parameters. Eg. at the top level in a script I declare:

<!-- May be passed in by the calling script -->
<xsl:param name="tab" select="home"/>
<xsl:param name="self" select="index.php"/>

The select attribute is a defult value in case it is not passed in.
From PHP I call it like this,

$params = array(
'tab' => isset($_GET['tab']) ? $_GET['tab'] : '',
'self' => $_SERVER['PHP_SELF']
);
$x = xslt_create();
$php = xslt_process($x,'index.xml','index.xsl',NULL,array (),$params);
xslt_free($x);
In the XSLT you can refer to the parameters as global variables:
ie. $tab, $self.

HTH,
Ben

--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
http://www.edginet.org/
Jul 20 '05 #2

well thanks for your reply but i did not undrestood what your code is
doing!!! :(

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
well thanks for your reply but i did not understood what your code is
doing...

thanks again

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
tsirman tsirman <ts*****@hotmail.com> writes:
well thanks for your reply but i did not undrestood what your code is
doing!!! :(


Well, perhaps you should have a look at

http://www.w3.org/TR/xslt#variables

and

http://uk2.php.net/xslt_create

--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
http://www.edginet.org/
Jul 20 '05 #5
yes i know but if u see in my code i can't put what u wrote somewhere
there:
my xsl file is:
---------------------
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="/">

<table cellSpacing="0" cellPadding="1" width="100%" bgColor="#f4f4f4"
border="0" height="100%">
<tbody>
<tr>
<td vAlign="top" colSpan="2" height="6"><img height="1"
src="images/white.gif" width="1"></img></td>
</tr>

<xsl:for-each select="result/categorylist/category">
<xsl:sort select="nodename"/>
<tr>
<td vAlign="top"><img src="images/d_tree_close.gif"></img></td>
<td>
<a class="nav"
HREF="http://tsirmans/babylonfiles/links.php?nodeid={nodeid}&amp;nodenam
e={nodename}">
<xsl:value-of select="nodename"/> (<xsl:value-of
select="sitecount"/>)</a>
</td>
</tr>
<tr>
<td colSpan="2"><img height="1" src="images/line.gif"
width="100%"></img></td>
</tr>
</xsl:for-each>
<tr>
<td colSpan="2"><img height="10" src="images/white.gif"
width="1"></img></td>
</tr>
</tbody>
</table>

</xsl:template>
</xsl:stylesheet>
------------------

and the php file is:
-------------------

<?php
$sql = mysql_query("
SELECT treeid
FROM tree_access
WHERE treename = '$treename'
");
$treeid = mysql_fetch_row($sql);

$xmlFile =
"http://localhost:6789/no_tree_dbgetchildrenlist?password=babylon&treeid
=".$treeid[0]."&nodeid=-1";
$xslFile = "data_get_tree_left.xsl";

// Create a new processor handle
$xslt = xslt_create() or die("Can't create XSLT handle!");

// Open the XML and XSL files
$xh = fopen($xmlFile, "r") or die("Can't open XML file");
$sh = fopen($xslFile, "r") or die("Can't open XSL file");

// Read in the XML and XSL contents
$xmlContent = fread($xh, 80000);
$xslContent = fread($sh, filesize($xslFile));

$args = array("/_xml" => iconv("ISO-8859-7","UTF-8",$xmlContent),
"/_xsl"=> iconv("ISO-8859-7","UTF-8",$xslContent) );

$data = xslt_process($xslt, "arg:/_xml", "arg:/_xsl", NULL, $args);
echo iconv("UTF-8","ISO-8859-7",$data);

xslt_free($xslt);
?>
------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #6
I'm assuming you want to replace the hard-coded HREF= with something
dynamic set in the PHP script.

tsirman tsirman <ts*****@hotmail.com> writes:
yes i know but if u see in my code i can't put what u wrote somewhere
there:
See below (untested code, but it might be right).
my xsl file is:
---------------------
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="links-script"/>
<xsl:template match="/">

<table cellSpacing="0" cellPadding="1" width="100%" bgColor="#f4f4f4"
border="0" height="100%">
<tbody>
<tr>
<td vAlign="top" colSpan="2" height="6"><img height="1"
src="images/white.gif" width="1"></img></td>
</tr>

<xsl:for-each select="result/categorylist/category">
<xsl:sort select="nodename"/>
<tr>
<td vAlign="top"><img src="images/d_tree_close.gif"></img></td>
<td>
<a class="nav"
HREF="http://tsirmans/babylonfiles/links.php?nodeid={nodeid}&amp;nodenam
e={nodename}">
change to HREF="{$links-script}?nodeid={nodeid}&amp;nodename={nodename}"
<xsl:value-of select="nodename"/> (<xsl:value-of
select="sitecount"/>)</a>
</td>
</tr>
<tr>
<td colSpan="2"><img height="1" src="images/line.gif"
width="100%"></img></td>
</tr>
</xsl:for-each>
<tr>
<td colSpan="2"><img height="10" src="images/white.gif"
width="1"></img></td>
</tr>
</tbody>
</table>

</xsl:template>
</xsl:stylesheet>
------------------

and the php file is:
-------------------

<?php
$sql = mysql_query("
SELECT treeid
FROM tree_access
WHERE treename = '$treename'
");
$treeid = mysql_fetch_row($sql);

$xmlFile =
"http://localhost:6789/no_tree_dbgetchildrenlist?password=babylon&treeid
=".$treeid[0]."&nodeid=-1";
$xslFile = "data_get_tree_left.xsl";

// Create a new processor handle
$xslt = xslt_create() or die("Can't create XSLT handle!");

// Open the XML and XSL files
$xh = fopen($xmlFile, "r") or die("Can't open XML file");
$sh = fopen($xslFile, "r") or die("Can't open XSL file");

// Read in the XML and XSL contents
$xmlContent = fread($xh, 80000);
$xslContent = fread($sh, filesize($xslFile));

$args = array("/_xml" => iconv("ISO-8859-7","UTF-8",$xmlContent),
"/_xsl"=> iconv("ISO-8859-7","UTF-8",$xslContent) );
$params = array('links-script'=>'http://tsirmans/babylonfiles/links.php');

(or set this dynamically using $_SERVER['HOST_NAME'] etc.)
$data = xslt_process($xslt, "arg:/_xml", "arg:/_xsl", NULL, $args);
$data = xslt_process($xslt, "arg:/_xml", "arg:/_xsl", NULL, $args, $params);
echo iconv("UTF-8","ISO-8859-7",$data);

xslt_free($xslt);
?>


Was it so hard?

--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
http://www.edginet.org/
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alexander Kienzle | last post by:
I'm new to Java programming. I'm developing a Servlet for tomcat which needs an external configuration file. With external I mean a file (in XML format) which is customizable and not contained in...
2
by: kathy | last post by:
What Application Configuration File is? And when/where/how to use it? Any documents on that? MSDN has somrthings scatter everywhere - hard to follow. thanks,
4
by: Jessard | last post by:
Hi Guys and Girls, I have a situation where I am wishing to deploy a .NET dll onto a number of servers. The classes in the DLL will be used by VBScripts. When one of the classes - Connection -...
3
by: Florida Coder | last post by:
I have the need to store some application specific configuration data to be used by a class library and or a windows service. I would like to do this in a fashion similar to the way we do with...
0
by: phillip | last post by:
This is interesting, I have attached my web.config file and the exception I have been logging. I created a library which provide data access to a database and a control system. The library is...
1
by: Ramanfromoz | last post by:
Hi, Developing a new we application. Everything okay on my local WIN XP PROFESSIONAL, IIS 5.0 running locally. The website is running smoothly. Now, the same code I am copying over to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
0
by: sean rogers | last post by:
hello im using the configuration block and have created the main config file for the application - the file that contains the paths to the other configuration sections i.e. - (my other...
6
by: Jeff Hegedus | last post by:
I have a dll that requires some configuration data. I put the configuration data in a custom configuration section in a config file that is loaded in the installation folder of the dll. If I...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.