ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Transforming XML from Moneyexpert with XLST

November 05, 2007 4:09pm

Subscribe [3]
  • #1 / Nov 05, 2007 4:09pm

    dlw

    17 posts

    Hi,

    I’ve been searching on here and various forums/search engines etc for a solution. I think it may be a tricky one. The output of this url is XML: http://webservices.moneyexpert.com/creditcard.asmx/Search?affiliateID=17&searchType=LowestIntroBalanceTransferRate&creditCardClass=Standard&currentBalance=2000&currentAPR=10&postcodeOutCode=SK7&postcodeInCode=3PH&pageSize=30&pageIndex=1

    The parameters will change depending on the users selection but I think I can deal with that by checking the segment passed. The site was originally going to be done in ASP and MoneyExpert do provide the following code:

    xmlURL = <a href="http://webservices.moneyexpert.com/creditcard.asmx/Search?affiliateID=17&searchType=LowestIntroBalanceTransferRate&creditCardClass=Standard&currentBalance=2000&currentAPR=10&postcodeOutCode=SK7&postcodeInCode=3PH&pageSize=30&pageIndex=1">http://webservices.moneyexpert.com/creditcard.asmx/Search?affiliateID=17&searchType=LowestIntroBalanceTransferRate&creditCardClass=Standard&currentBalance=2000&currentAPR=10&postcodeOutCode=SK7&postcodeInCode=3PH&pageSize=30&pageIndex=1</a>
            
            'XML http calls a URL and returns the text from that request (either xml for a web service or html for a webpage)
            set xml = Server.CreateObject("Microsoft.XMLHTTP")
            'populate the XmlHttp object with the xml returned from the webservice
            xml.Open "GET", xmlURL, False
            xml.Send
            
            response.write(xmlURL)
            
            strWebServiceReturnedXml = xml.responseText
            ' this will not render in a browser of course, look at it in the ViewSource to see the XML
            'Response.Write "xmlStart" & strWebServiceReturnedXml & "xmlEnd"
            
            'load the web service xml into an XmlDom
            set XMLdoc  = server.CreateObject("MSXML.DOMDocument")
            XMLdoc.loadXML strWebServiceReturnedXml
            
            'load a stylesheet from a file into an XmlDom
            set XSLTdoc = server.CreateObject("MSXML.DOMDocument")
            XSLTdoc.load server.MapPath("creditCard.xslt")
            
            'transform the XML using the XSLT, it returns a string
            strHtml = XMLdoc.transformNode(XSLTdoc)
            Response.Write  strHtml

    Essentially I need to do the above but in PHP and being a newbie when it comes to both PHP and EE I am really struggling. EE has been great for the rest of it with various weblogs etc but this could be a stumbling block for me.

    TIA,
    Darren

  • #2 / Nov 06, 2007 7:29am

    dlw

    17 posts

    Just to let you know that this is now fixed, all I had to do was turn on the relevant xsl line ‘extension=php_xsl.dll’ in the php.ini and use the following code:

    <?php
    $xml = new DomDocument;
    $xml->load('http://webservices.moneyexpert.com/creditcard.asmx/Search?affiliateID=17&searchType=LowestIntroBalanceTransferRate&creditCardClass=Standard&currentBalance=2000&currentAPR=10&postcodeOutCode=SK7&postcodeInCode=3PH&pageSize=30&pageIndex=1');
    
    $xsl = new DomDocument;
    $xsl->load('http://therichlady.com/creditCard.xslt');
    
    $xslt = new XsltProcessor;
    $xslt->importStylesheet($xsl);
    
    $transformation = $xslt->transformToXml($xml);
    echo $transformation; 
    }
    
    ?>

    I have to say thanks to the people in this thread: http://www.sitepoint.com/forums/show…t=php5+xml+xsl as it was a massive help. I just can’t believe it was that simple.

    Cheers,
    Darren.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases