Sablotron and remote XML File

samfox
samfox used Ask the Experts™
on
Hi,

I am new to the site and have come accross many helpful articles in my quest however I am trying to transform a the following remote XML file:
http://icwebdesign.overture.com/d/search/p/icwebdesign/xml/uk/?mkt=uk&Keywords=loans&maxCount=3

with this Stylesheet

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" omit-xml-declaration="no"/ encoding="iso-8859-1"/>

  <!-- ************************************************** -->
  <xsl:template match="Results">
        <xsl:apply-templates select="ResultSet"/>
  </xsl:template>

  <!-- ************************************************** -->
  <xsl:template match="ResultSet">
    <xsl:choose>
      <xsl:when test="@id='searchResults'">

              <xsl:apply-templates select="Listing"/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <!-- ************************************************** -->
  <xsl:template match="NextArgs">
    <a href="test1.pl?{current()}">Next Page</a>
  </xsl:template>

  <!-- ************************************************** -->
  <xsl:template match="PrevArgs">
    <a href="test1.pl?{current()}">Last Page</a>
  </xsl:template>

  <!-- ************************************************** -->
  <xsl:template match="Listing">
     <TABLE width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#CCCCFF">
  <TR align="left" valign="top">
    <TD><a href="{@clickUrl}" target="_blank" class="bluelinkbold">
          <xsl:value-of select="@title"/></a></TD>
  </TR>
</TABLE>
 <TABLE width="100%" border="0" cellspacing="2" cellpadding="0" bgcolor="#FBFBFF">
  <TR>
    <TD width="4%" align="left" valign="top">
      <TABLE width="30" border="0" cellspacing="0" cellpadding="4">
        <TR>
          <TD width="20" align="left" valign="middle"></TD>
        </TR>
        <TR>
          <TD width="20" align="left" valign="middle"></TD>
        </TR>
        <TR>
          <TD width="20" align="left" valign="middle"></TD>
        </TR>
        <TR>
          <TD width="20" align="left" valign="middle"></TD>
        </TR>
      </TABLE>
    </TD>
    <TD width="96%" align="left" valign="top"  class="normaltxt">
      <xsl:value-of select="@description"/>
    </TD>
  </TR>
</TABLE>
     
     
     
      <xsl:text> </xsl:text>
     <!-- Disable the escape of < and > so our a href tag will go -->
     <!-- through as html and not &lt; &gt;                       -->
     <xsl:value-of disable-output-escaping="yes" select="@bidText"/>
   
  </xsl:template>


</xsl:stylesheet>

Using the following php code:

<?php

    // Creating a XSLT Processor
    // "$xsltproc" is the XSLT processor resource.
    $xsltproc = xslt_create();

$OpenFile = fopen("http://www.great-british-pages.co.uk/cgi-bin/xml/overture.pl?query=$term", "r");
$RetrieveFile = fread($OpenFile, 200000);
    // Processing the two files
    $result = xslt_process($xsltproc, $RetrieveFile, 'overture1.xsl' );

    // If we have a result then display the contents
    // If not then die and display the error information
    if( $result ) {    
            echo "$result";
    }
    else {    
        die( sprintf( "The XSLT processor failed [%d]: %s", xslt_errno( $xsltproc ), xslt_error( $xsltproc ) ) );
    }

    // Free up the XSLT Processor
    xslt_free( $xsltproc );

?>

After trying many many many different variations i keep hitting my head up against the following error code:

Warning: Sablotron error on line 3: XML parser error 4: not well-formed (invalid token) in /usr/local/home/httpd/1.php on line 10
The XSLT processor failed [2]: XML parser error 4: not well-formed (invalid token)


Any pointers would be great

Cheers
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,
Sablotron may give this "malformed" error if your XML (or XSLT) contain charcters that are invalid for the current encoding as well as any if the reserverd characters <>& as text-values.
From the link above, the XML result document contains at least one & wich is not encoded as &amp;
here the &xargs querystring parameter:
<NextArgs>Keywords=loans&xargs=00u3hs9yoaKCstSjWzNVAAMrVjzLJy1NcwzBgABep%2Ffgc%3D</NextArgs>
must be
&amp;xargs
to be XML compliant.
Other issues are special characters like german umlauts (äöüß) or other non-us ascii characters.

You have to make sure, the encoding of the file is the same as the one given in the <?xml version="1.0" encoding="iso-8859-1"?>
It seems like iso-8859-1 will not suffice whenusing non-ascii characters (if any appear in your XML document).
Usually UTF-8 will work with äöüßéáû and alike IF the XML document IS real UTF-8.

You may need to convert your XML document in your code using iconv() before it's passed over to Sablotron:
$RetrieveFile = iconv("iso-8859-1", "UTF-8", $RetrieveFile);
and make sure all single <,> and & characters are converted to XML entities &lt; &gt; &amp;

Hope this helps

CirTap


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial