Page 1 of 1

XML Hell

Posted: Thu Apr 01, 2004 2:39 am
by phpnovice
Hi im trying to use xslt in PHP to pass a xml doc and output a html page, and i had it working for about 30 secs now i only get the same error message for hours on end no matter what i do. the error is (69: Unknown encoding '') so i have an html form with a file select box and a submit button method="post", enctype="multipart/form-data". then i perform the transform like so in php

Code: Select all

<?php
function transformxml ($sourcexml, $sourcexsl)
{
	$sourcexml = 'file://' . $sourcexml;
	$sourcexsl = 'file://' . $sourcexsl;
	$xslt = xslt_create();
	
	//process the document
	
	if(!$result = @xslt_process($xslt, $sourcexml, $sourcexsl))
	{
		print ("Error: " . xslt_error($xslt) . " Error Num: " . xslt_errno($xslt));
		die();
	}

	xslt_free($xslt);
	return $result;
}
//get source file locations
$sourcexsl = $_POST["delnotexsl"];
$sourcexml = $_POST["delnotexml"];
//delnotexml is the post name of the file and delnotexsl is a hidden 
//field with the location of my xsl doc

print (transformxml($sourcexml, $sourcexsl));

?>
And i know the xsl doc works but here it is anyway:
Admin Edit: added tags around the XSLT.[/size][/color]

Code: Select all

&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
     &lt;xsl:output method="html" /&gt;
   &lt;xsl:template match="/"&gt;
      &lt;html&gt;
         &lt;body&gt;
         &lt;h3&gt;Please select a dvd to add to the database&lt;/h3&gt;
            &lt;table&gt;
           &lt;tr&gt; &lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Duration&lt;/th&gt;&lt;th&gt;Release Date&lt;/th&gt;&lt;th&gt;Price&lt;/th&gt;&lt;th&gt;Quan.&lt;/th&gt;&lt;/tr&gt;
            &lt;xsl:for-each select="//DVD"&gt;
            &lt;tr&gt;
               &lt;form action="insertfromxml.php" method="post"&gt;
                  &lt;xsl:apply-templates select="DVD_TITLE"/&gt;
                  &lt;xsl:apply-templates select="DVD_DURATION"/&gt;
                  &lt;xsl:apply-templates select="DVD_RELEASE_DATE"/&gt;
                  &lt;xsl:apply-templates select="DVD_PRICE"/&gt;
                  &lt;xsl:apply-templates select="QUANTITY"/&gt;
              &lt;td&gt; &lt;input type="submit" value="Insert This DVD" /&gt;&lt;/td&gt;
               &lt;/form&gt;
               &lt;/tr&gt;
            &lt;/xsl:for-each&gt;
            &lt;/table&gt;
         &lt;/body&gt;
      &lt;/html&gt;
   &lt;/xsl:template&gt;
  &lt;xsl:template match="DVD_TITLE"&gt;
      &lt;td&gt;
      &lt;input type="text" size="30" name="txtTITLE"&gt;
         &lt;xsl:attribute name="value"&gt;
            &lt;xsl:value-of select="."/&gt;
          &lt;/xsl:attribute&gt;
      &lt;/input&gt;
      &lt;/td&gt;
   &lt;/xsl:template&gt;
   &lt;xsl:template match="DVD_DURATION"&gt;
   &lt;td&gt;
      &lt;input type="text" size="5" name="txtDURATION"&gt;
         &lt;xsl:attribute name="value"&gt;
            &lt;xsl:value-of select="."/&gt;
          &lt;/xsl:attribute&gt;
      &lt;/input&gt;
      &lt;/td&gt;
   &lt;/xsl:template&gt;
      &lt;xsl:template match="DVD_RELEASE_DATE"&gt;
      &lt;td&gt;
      &lt;input type="text" size="15" name="txtRELEASE"&gt;
         &lt;xsl:attribute name="value"&gt;
            &lt;xsl:value-of select="."/&gt;
          &lt;/xsl:attribute&gt;
      &lt;/input&gt;
      &lt;/td&gt;
   &lt;/xsl:template&gt;
      &lt;xsl:template match="DVD_PRICE"&gt;
      &lt;td&gt;
      &lt;input type="text" size="6" name="txtPRICE"&gt;
         &lt;xsl:attribute name="value"&gt;
            &lt;xsl:value-of select="."/&gt;
          &lt;/xsl:attribute&gt;
      &lt;/input&gt;
   &lt;/td&gt;
   &lt;/xsl:template&gt;
      &lt;xsl:template match="QUANTITY"&gt;
      &lt;td&gt;
      &lt;input type="text" size="4" name="txtQUANTITY"&gt;
         &lt;xsl:attribute name="value"&gt;
            &lt;xsl:value-of select="."/&gt;
          &lt;/xsl:attribute&gt;
      &lt;/input&gt;
   &lt;/td&gt;
   &lt;/xsl:template&gt;
   &lt;/xsl:stylesheet&gt;
So is it this or is it my xml doc encoding or what, ive looked around and alot of people have this problem but sort it out through the config of php, which i have no option in as its a uni server.
Thanks for any help

James Baker

Posted: Thu Apr 01, 2004 2:52 am
by twigletmac
What is your XML encoding?

Mac

Posted: Thu Apr 01, 2004 2:59 am
by phpnovice
this is the sample xml doc i am trying to operate on.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<Delivery_Note>
	<DVD>
		<DVD_TITLE>Joe Bloggs Big Day Out</DVD_TITLE>
		<DVD_DURATION>124</DVD_DURATION>
		<DVD_RELEASE_DATE>2003-01-25</DVD_RELEASE_DATE>
		<DVD_PRICE>13.99</DVD_PRICE>
		<QUANTITY>40</QUANTITY>
	</DVD>
	<DVD>
		<DVD_TITLE>Terminator 3</DVD_TITLE>
		<DVD_DURATION>100</DVD_DURATION>
		<DVD_RELEASE_DATE>1998-03-11</DVD_RELEASE_DATE>
		<DVD_PRICE>10.50</DVD_PRICE>
		<QUANTITY>25</QUANTITY>
	</DVD>
</Delivery_Note>
ive also tried iso standard too but no joy. oh and tried wrapping them with ' instead of ". and a million other little syntax changes. cant seem to get anything other than unknown encoding!

Posted: Thu Apr 01, 2004 3:31 am
by twigletmac
What do you get if you leave out the encoding information?

Mac

Posted: Thu Apr 01, 2004 3:35 am
by phpnovice
just tried it, get exactly the same, i dont understand cause i had it working for a while yesterday and now i cant even get back to there!
Weird. any ideas to what it might be.

Ok i just uploaded my order1.xml to the server then specified an exact path to it instead of passing it from the form and it works fine, but thats not much use, i need to be able to select the right file. im pretty sure its to do with finding the file properly now, maybe someone has some idea what is going on with files.

my html form is like so

Code: Select all

<h3>Please select the location of the delivery note you wish to process</h3><br />
<br />
<form name="selectdelnote" method="post" action="transformxml.php" enctype="multipart/form-data">
<input type ="file" name = "delnotexml"><br />
<input type = "submit" value = "Submit">
<input type = "hidden" name="delnotexsl" value="/home/bj253/public_html/newdvdform.xsl">
</form>

Posted: Thu Apr 01, 2004 4:00 am
by phpnovice
GOT IT!!
used $_FILES['userfile']['tmpname'] to pass it and it works a treat. cheers for your help.