Hello,
I am stuck. The following asp accepts and passes xsl parameters from a web page which then transforms my xsl, but for the life of me I can't get php to do the same. I want to be strictly LAMP, no $MS stuff.
selectmenu.asp
<%
Dim xslDoc, xmlDoc
Dim name
sname=Request.QueryString("name")
set xmlDoc = server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
set xslDoc = server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
xmlDoc.async = False
xslDoc.async = False
xmlDoc.load server.mapPath("index.xml")
xslDoc.load server.mapPath("index.xsl")
Set template = Server.CreateObject("MSXML2.XSLTemplate.3.0")
Set template.stylesheet = xslDoc
Set proc = template.createProcessor
proc.input = xmlDoc
proc.addParameter "name", sname
proc.transform
Response.Write proc.output
%>
index.xsl
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml"
doctype-public="-//W3C//DTD XHTML 1.1//EN" indent="yes" encoding="utf-8" />
<xslaram name="name" select="'Home'" />
<xslaram name="Ncols" select="'2'" />
<xsl:template match="/">
<html>
<head>
<meta name="description" content="Praise Cathedral - Church of God, Palm Bay Florida" />
<meta name="keywords" content="praise cathedral, church of God, palm bay, brevard county, christian fellowship" />
<title><xsl:value-of select="title" /></title>
<link href=http://www.phpbuilder.com/board/archive/index.php/"praise.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="header" align="center" valign="top"><img src=http://www.phpbuilder.com/board/archive/index.php/"images/praiselogo.gif" alt="Praise Cathedral - Church of God, Palm Bay Florida" /><hr /></div>
<div class="lsidebar" align="left">
<br /><br />
<ul align="left"><xsl:for-each select="site/menus/menu">
<li align="left"><strong><a><xsl:attribute name="href">selectmenu.php?name=<xsl:value-of select="@name" />
</xsl:attribute><xsl:value-of select="@name" /></a></strong><br /><br /></li></xsl:for-each>
</ul></div>
<div class="main" align="center"><xsl:apply-templates select="site/menus/menu[@name=$name]" /><br />
<div class="footer" align="center">Site created and maintained by <a href=http://www.phpbuilder.com/board/archive/index.php/"http://sunshinearcade.christianpatriot.us" target="blank">Sunshine Arcade</a><br /> Copyright?2000</div></div>
</body>
</html>
</xsl:template>
<xsl:template match="announcement"><br />
<div>
<xsl:for-each select="."><h3 align="center"><xsl:value-of select="./@name" /></h3>
<p align="left"><xsl:apply-templates />
</p>
<hr />
</xsl:for-each>
</div>
...
</xsl:template>
</xsl:stylesheet>
selectmenu.php
<?
$name=$_GET['name'];
//$name = $_REQUEST['name'];
$xp = new XsltProcessor();
// create a DOM document and load the XSL stylesheet
$xsl = new DomDocument;
$xsl->load('index.xsl');
// import the XSL styelsheet into the XSLT process
$xp->importStylesheet($xsl);
// create a DOM document and load the XML data
$xml_doc = new DomDocument;
$xml_doc->load('index.xml');
$xp->setParameter('', 'name', $name));
if ($html = $xp->transformToXML($xml_doc)) {
echo $html;
} else {
trigger_error('XSL transformation failed.', E_USER_ERROR);
} if
?>
index.php calls the xml and xsl files and renders them correctly. The links it creates reflect that the link urls are (for example) selectmenu.php?name=Services but this doesn't seem to get passed into selectmenu.php or passed back to the xsl to display the relevant page. Instead the "Home" page (the default xslarameter) is displayed. Putting $ in place of @ in the xsl causes a blank page to be rendered and a myriad of other tries also don't produce the right results. The preceeding code might not make sense as I gave up exasperated to write this.
Please help as I don't want to revert back to asp and all that that encompasses.
Fedora Core 5
PHP 5.2.0
./configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-gd' '--with-gettext' '--with-xsl=/usr/lib' '--with-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-regex=system' '--with-zlib' '--with-curl' '--with-openssl' '--enable-mbstring'
Apache 2.2.3
I do think I've tried everything, even to the point of being ridiculous. Sorry for the smilies in the code; not my fault.
TIA
PaulJust needed a couple days away from the problem.
This works like a champ except I want to get rid of my urls appearing as; for example
<!-- w --><a class="postlink" href="http://www.example.com/selectmenu.php?name=events">www.example.com/selectmenu.php?name=events</a><!-- w -->
instead of <!-- w --><a class="postlink" href="http://www.example.com">www.example.com</a><!-- w -->
<?
$name=$_GET['name'];
//$name = $_REQUEST['name'];
$xp = new XsltProcessor();
// create a DOM document and load the XSL stylesheet
$xsl = new DomDocument;
$xsl->load('index.xsl');
// import the XSL styelsheet into the XSLT process
$xp->importStylesheet($xsl);
// create a DOM document and load the XML data
$xml_doc = new DomDocument;
$xml_doc->load('index.xml');
//$xp->setParameter('','name', $name);
//$proc->transform;
$xp->setParameter('', 'name', $name);
if ($html = $xp->transformToXML($xml_doc)) {
echo $html;
} else {
trigger_error('XSL transformation failed.', E_USER_ERROR);
}
I am stuck. The following asp accepts and passes xsl parameters from a web page which then transforms my xsl, but for the life of me I can't get php to do the same. I want to be strictly LAMP, no $MS stuff.
selectmenu.asp
<%
Dim xslDoc, xmlDoc
Dim name
sname=Request.QueryString("name")
set xmlDoc = server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
set xslDoc = server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
xmlDoc.async = False
xslDoc.async = False
xmlDoc.load server.mapPath("index.xml")
xslDoc.load server.mapPath("index.xsl")
Set template = Server.CreateObject("MSXML2.XSLTemplate.3.0")
Set template.stylesheet = xslDoc
Set proc = template.createProcessor
proc.input = xmlDoc
proc.addParameter "name", sname
proc.transform
Response.Write proc.output
%>
index.xsl
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="xml"
doctype-public="-//W3C//DTD XHTML 1.1//EN" indent="yes" encoding="utf-8" />
<xslaram name="name" select="'Home'" />
<xslaram name="Ncols" select="'2'" />
<xsl:template match="/">
<html>
<head>
<meta name="description" content="Praise Cathedral - Church of God, Palm Bay Florida" />
<meta name="keywords" content="praise cathedral, church of God, palm bay, brevard county, christian fellowship" />
<title><xsl:value-of select="title" /></title>
<link href=http://www.phpbuilder.com/board/archive/index.php/"praise.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="header" align="center" valign="top"><img src=http://www.phpbuilder.com/board/archive/index.php/"images/praiselogo.gif" alt="Praise Cathedral - Church of God, Palm Bay Florida" /><hr /></div>
<div class="lsidebar" align="left">
<br /><br />
<ul align="left"><xsl:for-each select="site/menus/menu">
<li align="left"><strong><a><xsl:attribute name="href">selectmenu.php?name=<xsl:value-of select="@name" />
</xsl:attribute><xsl:value-of select="@name" /></a></strong><br /><br /></li></xsl:for-each>
</ul></div>
<div class="main" align="center"><xsl:apply-templates select="site/menus/menu[@name=$name]" /><br />
<div class="footer" align="center">Site created and maintained by <a href=http://www.phpbuilder.com/board/archive/index.php/"http://sunshinearcade.christianpatriot.us" target="blank">Sunshine Arcade</a><br /> Copyright?2000</div></div>
</body>
</html>
</xsl:template>
<xsl:template match="announcement"><br />
<div>
<xsl:for-each select="."><h3 align="center"><xsl:value-of select="./@name" /></h3>
<p align="left"><xsl:apply-templates />
</p>
<hr />
</xsl:for-each>
</div>
...
</xsl:template>
</xsl:stylesheet>
selectmenu.php
<?
$name=$_GET['name'];
//$name = $_REQUEST['name'];
$xp = new XsltProcessor();
// create a DOM document and load the XSL stylesheet
$xsl = new DomDocument;
$xsl->load('index.xsl');
// import the XSL styelsheet into the XSLT process
$xp->importStylesheet($xsl);
// create a DOM document and load the XML data
$xml_doc = new DomDocument;
$xml_doc->load('index.xml');
$xp->setParameter('', 'name', $name));
if ($html = $xp->transformToXML($xml_doc)) {
echo $html;
} else {
trigger_error('XSL transformation failed.', E_USER_ERROR);
} if
?>
index.php calls the xml and xsl files and renders them correctly. The links it creates reflect that the link urls are (for example) selectmenu.php?name=Services but this doesn't seem to get passed into selectmenu.php or passed back to the xsl to display the relevant page. Instead the "Home" page (the default xslarameter) is displayed. Putting $ in place of @ in the xsl causes a blank page to be rendered and a myriad of other tries also don't produce the right results. The preceeding code might not make sense as I gave up exasperated to write this.
Please help as I don't want to revert back to asp and all that that encompasses.
Fedora Core 5
PHP 5.2.0
./configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-gd' '--with-gettext' '--with-xsl=/usr/lib' '--with-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-regex=system' '--with-zlib' '--with-curl' '--with-openssl' '--enable-mbstring'
Apache 2.2.3
I do think I've tried everything, even to the point of being ridiculous. Sorry for the smilies in the code; not my fault.
TIA
PaulJust needed a couple days away from the problem.
This works like a champ except I want to get rid of my urls appearing as; for example
<!-- w --><a class="postlink" href="http://www.example.com/selectmenu.php?name=events">www.example.com/selectmenu.php?name=events</a><!-- w -->
instead of <!-- w --><a class="postlink" href="http://www.example.com">www.example.com</a><!-- w -->
<?
$name=$_GET['name'];
//$name = $_REQUEST['name'];
$xp = new XsltProcessor();
// create a DOM document and load the XSL stylesheet
$xsl = new DomDocument;
$xsl->load('index.xsl');
// import the XSL styelsheet into the XSLT process
$xp->importStylesheet($xsl);
// create a DOM document and load the XML data
$xml_doc = new DomDocument;
$xml_doc->load('index.xml');
//$xp->setParameter('','name', $name);
//$proc->transform;
$xp->setParameter('', 'name', $name);
if ($html = $xp->transformToXML($xml_doc)) {
echo $html;
} else {
trigger_error('XSL transformation failed.', E_USER_ERROR);
}