Results 1 to 1 of 1

Thread: PHP variable in JavaScript

  1. #1
    Join Date
    Mar 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP variable in JavaScript

    Hi,

    Anyone any idea why the JavaScript code below displays the variable I explicitly declared but not the variable defined by the result of the XSL transform? i.e. when you change $foo to $earth there is no output. (my xsl fragment is at the bottom of this message).

    Thanks.

    PHP Code:

    <?php
    //XMLXSL Transformation class
    require_once('includes/MM_XSLTransform/MM_XSLTransform.class.php');
    ?>
    <html>

    <?php
    $mm_xsl = new MM_XSLTransform();
    $mm_xsl->setXML("http://feeds.feedburner.com/usgs/eqs1day-M25");
    $mm_xsl->setXSL("earthquake.xsl");
    $earth = $mm_xsl->Transform();
    $foo = 'bar';
    ?>

    <?php
    echo $earth;
    echo $foo;
    ?>

    <script>
    var a = "<?php echo $foo;?>";
    document.write(a);
    </script>

    </html>



    XSL fragment:

    <?xml version="1.0" encoding="iso-8859-1"?><!-- DWXMLSource="http://feeds.feedburner.com/usgs/eqs1day-M25" -->
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "*">
    <!ENTITY copy "">
    <!ENTITY reg "">
    <!ENTITY trade "">
    <!ENTITY mdash "">
    <!ENTITY ldquo "">
    <!ENTITY rdquo "">
    <!ENTITY pound "">
    <!ENTITY yen "">
    <!ENTITY euro "">
    ]>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:atom10="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <xsl:output method="html" encoding="iso-8859-1"/>
    <xsl:param name="ItemsPerPage" select="20"/>
    <xsl:template match="/">

    <xsl:for-each select="rss/channel/item">
    <xsl:sort select="title" order="descending"/>
    <xsl:if test="position() &lt; 2">
    <xsl:value-of select="title"/>
    </xsl:if>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    Last edited by ddadmin; 03-30-2006 at 07:10 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •