configuration of xsl file

tsirman

Usenet Archive
Joined
Apr 29, 2004
Messages
3
Reaction score
0
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....
 

Ben Edgington

Usenet Archive
Joined
Mar 18, 2004
Messages
45
Reaction score
0
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
 

tsirman tsirman

Usenet Archive
Joined
Apr 30, 2004
Messages
3
Reaction score
0
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);
?>
 

Ben Edgington

Usenet Archive
Joined
Mar 18, 2004
Messages
45
Reaction score
0
I'm assuming you want to replace the hard-coded HREF= with something dynamic set in the PHP script.

tsirman tsirman said:
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: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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top