NYCPHP Meetup

NYPHP.org

[nycphp-talk] Transforming XML with XSL (XsltProcessor problems)

Peter Sawczynec ps at blu-studio.com
Wed Mar 11 05:30:57 EDT 2009


In your XSL styleshhet looks to me like you are matching on an element
called "Data" while the XML has an element called "DataItem". And in
your XPATH sample that gets a result you check for the element
"DataItem". 

Warmest regards, 
 
Peter Sawczynec 
Technology Dir.
blūstudio 
941.893.0396
ps at blu-studio.com 
www.blu-studio.com 


-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of Ben Sgro
Sent: Tuesday, March 10, 2009 6:33 PM
To: NYPHP Talk
Subject: [nycphp-talk] Transforming XML with XSL (XsltProcessor problems)

Hello,

My PHP code is:
---------------------

        $xml = new DOMDocument;
        $xml->load($this->_payload);       

           $xsltProcessor = new XsltProcessor();
        $xsl = new DomDocument;
        $xsl->load('../lib/Transformations/text.xsl');
       
        $xsltProcessor->importStylesheet($xsl);
        $result = $xsltProcessor->transformToXml($xml);
   
        return $result;


My XSL is:
--------------

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
 xmlns="http://www.w3.org/1999/xhtml"
 >
<xsl:template match="/">
<xsl:element name="Data">
<xsl:element name="AccountNumber"><xsl:value-of 
select="//DataItem[@name='AccountNumber']/@value"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>


And my XML is:
---------------------

<ProfileRequest templateId="1" submitUser="asdf" 
submitDateTime="2009-01-12T17:32:46">
    <DataItem name="AccountNumber" value="600978"/>
</ProfileRequest>



The $result is:
-----------------

<?xml version="1.0"?>
<Data 
xmlns="http://www.w3.org/1999/xhtml"><AccountNumber></AccountNumber></Da
ta>

So, as you can see the AccountNumber is missing. This XSL/XML works fine

in Author (XML Tool).
Any ideas why this would fail? Also, the Xpath 
(//DataItem[@name='AccountNumber']/@value) works
if I make the XML a simpleXML object and call xpath on it.

Thanks for your help!

- Ben
_______________________________________________
New York PHP User Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/show_participation.php





More information about the talk mailing list