Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP XSL to PHP XSL

Status
Not open for further replies.

irate

Programmer
Jan 29, 2001
92
0
0
GB
I am trying to convert an XML & XSL script from ASP to PHP.

I can get the XML and XSL to work fine, but for ASP i am using msxml to apply javascript functions.

Of course I cannot use that in PHP, so I was wondering if there is a way to do the same thing?

Here is the ASP:

Code:
<%
  dim url
      url = "file.xml"
  dim xmlhttp
  set xmlhttp = server.createObject("msxml2.serverXMLHttp")
      xmlhttp.open "GET", url, false
      xmlhttp.send()
      rspxml = xmlhttp.responseText
  set xmlhttp = nothing
  dim xmldoc
  set xmldoc = createObject("msxml2.DOMDocument")
      xmldoc.Async = false
      xmldoc.loadXML(rspxml)
  dim style
  set style = createObject("msxml2.DOMDocument")
      style.async = false
      style.load(server.mapPath("file.xsl"))
  dim outHtml
      outHtml = xmldoc.transformNode (style)
  set xmldoc = nothing
  set style = nothing
%>

and the XSL:

Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns:msxsl="urn:schemas-microsoft-com:xslt">
 <msxsl:script language="JScript" implements-prefix="user">
  <![CDATA[
   function ChopURL(url)
    {
     var retstr, i, pos;
     retstr = unescape(url);
     pos = retstr.indexOf("://", 1);
     if(pos >= 0)
        retstr = retstr.substring(pos + 3, retstr.length);
     pos = retstr.indexOf("/", 1);
     if(pos >= 0)
        retstr = retstr.substring(0, pos);
        retstr = LeftStr(retstr, 50);
        return retstr;
    }
   ]]>
  </msxsl:script>
  <xsl:template match="/">
   <a>
    <xsl:attribute name="href"><xsl:value-of select="user:ChopURL(string(URL))"/></xsl:attribute>
   </a>
  </xsl:template>
</xsl:stylesheet>

and the PHP im using:

Code:
<?
  $xml = new DOMDocument;
  $xml->load('file.xml');
  $xsl = new DOMDocument;
  $xsl->load('file.xsl');
  $proc = new XSLTProcessor;
  $proc->importStyleSheet($xsl);
  echo $proc->transformToXML($xml);
?>

This doesnt work currently because of the msxml part, but if I take that out its does work.

I need a replacement for it that will work witht he PHP XSL.

Thanks in advance to any help
 
Try this :
to put right here in quick code.

Code:
<? // Xml and XSL files 
$xml_file = "complex.xml"; 
$xsl_file = "complex.xsl"; 

// Allocate a new XSLT processor 
$xh = xslt_create();
$fileBase = 'file://' . getcwd () . '/';
xslt_set_base ( $xh, $fileBase );

// Process the document 
$result = xslt_process($xh, $xml_file, $xsl_file); 
if (!$result) { 
	// Something croaked. Show the error
	echo 'XSLT processing error: ' .xslt_error($xh) ; 
} else { 
	// Output the resulting HTML
	 echo $result; 
} 

// Destroy the XSLT processor 

xslt_free($xh);
?>

Karl Blessing
PHP/MySQL Developer
 
Sorry, I think you miss-understood.

The PHP works, it gets the XML file and transforms it with the XSL fine, I know it has no error trapping or fancy bits; it’s just a simple script.

What I am looking for is a way to include JavaScript functions in the XSL as in my example XSL.

This works in ASP because it uses the MSXML namespace, but obviously I cannot use that in the XSL with PHP as the processor does not support it.

I was hoping someone could show me a way to use JavaScript functions in an XSL with PHP.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top