Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    XML XSLT and PHP AddType Question

    Hello,
    I am trying to come up with a system to style sitemaps. I have everything working except I can't execute <?php> tags inside the .xslt document.
    I think that I am not enabling something in the .htaccess but, I just can't figure it out. Help would be very awesome.

    MODULES
    I have this extension loaded.... do I need others?
    php_xsl.dll


    Here are my various pages.

    .XML
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <?xml-stylesheet type="application/xslt+xml" href="/stylesheets/sitemap.xsl" ?>
    
    <urlset>
    <url>
    <loc>
    </loc>
    <lastmod>
    </lastmod>
    </url>
    </urlset>
    .XSL
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
    
    <xsl:output method="html"/>
    <xsl:template match="/">
    
    <html>
    <?php $thisPage="sitemap"; ?>
    
    <head>
    <title><?php echo $thisPage ?></title>
    <?php include"./includes/meta.php"?>
    <?php include"./includes/link.php"?>
    </head>
    
    <body>
    <div id="wrapper">
    
    <div id="tank" >
    <h1><?php echo $thisPage ?></h1>
    <h2></h2>
    	<?php include"./includes/header.php" ?>
    
    	<div id="nav">
    	
    	<?php include"./includes/nav.php" ?>
    	</div><!--End of nav-->
    
    <div id="leftcolumn">
    
    <h1>sitemap</h1>
        <table border="1">
        <tr>
          <th align="left">URLs</th>
          <th align="left">Last Modified</th>
        </tr>
        <xsl:for-each select="urlset/url">
        <tr>
          <td><xsl:value-of select="loc"/></td>
          <td><xsl:value-of select="lastmod"/></td>
        </tr>
        </xsl:for-each>
        </table>
    
    
    </div> <!--End of Left Column-->
    
    <div id="rightcolumn">
    </div> <!--End of Right Column-->
    
    <div class="clear"></div>
    
    <div id="footer" style="margin-top: 10px;">
    <?php include"./includes/footer.php" ?>	
    </div><!--End of Footer-->
    </div><!--End of tank-->
    	</div><!--End of Wrapper-->
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    .HTACCESS (I have tried several combinations of the types below)
    Code:
    AddType x-mapp-php5 .html .htm .xsl .xml
    AddType application/x-httpd-php .xml .xsl .html
    AddType	text/xsl .xslt .xsl
    AddType	application/xml	.xml
    AddType	application/xhtml+xml .xhtml

  • #2
    Regular Coder byuhobbes85's Avatar
    Join Date
    Oct 2006
    Location
    Ames, Iowa, USA
    Posts
    116
    Thanks
    9
    Thanked 4 Times in 4 Posts

    Question

    I have had a similar problem. I have an XML file that is successfully transformed using an XSL stylesheet, but when I copy that XML into a PHP file (and echo out the tags starting with <? ) it does not transform the XML.

    I'm running IIS, so I don't know if .htaccess will work for me.

    I have included examples below. The XSL stylesheet doesn't do much, I was just trying to do a case-in-point.

    Here is the first bit of the plain XML.
    Code:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="ScoTest.php"?>
    
    <TestItems>
    <item>
    	<itemId>0-48de9c82a963f</itemId>
    	<itemType>scriptMasculineFeminine</itemType>
    	<instructions>Identify whether the following word is masculine or feminine.</instructions>
    	<stimulus>
    		<stimulusType>script</stimulusType>
    		<stimulusLanguage>arabic</stimulusLanguage>
    		<stimulusValue> أنتِ </stimulusValue>
    	</stimulus>
    	<responses>
    		<responseType>text/script</responseType>
    		<responseLanguage>English</responseLanguage>
    		<response>
    			<correct>false</correct>
    			<responseValue>masculine</responseValue>
    		</response>
    		<response>
    			<correct>true</correct>
    			<responseValue>feminine</responseValue>
    		</response>
    	</responses>
    </item>
    ...
    ...
    Here is the first bit of the PHP.
    PHP Code:
    <?php
    echo '<?xml version="1.0"?>\n';
    echo 
    '<?xml-stylesheet type="text/xsl" href="ScoTest.xsl"?>';
    ?>

    <TestItems>
    <item>
        <itemId>0-48de9c82a963f</itemId>
        <itemType>scriptMasculineFeminine</itemType>
        <instructions>Identify whether the following word is masculine or feminine.</instructions>
        <stimulus>
            <stimulusType>script</stimulusType>
            <stimulusLanguage>arabic</stimulusLanguage>
            <stimulusValue> أنتِ </stimulusValue>
        </stimulus>
        <responses>
            <responseType>text/script</responseType>
            <responseLanguage>English</responseLanguage>
            <response>
                <correct>false</correct>
                <responseValue>masculine</responseValue>
            </response>
            <response>
                <correct>true</correct>
                <responseValue>feminine</responseValue>
            </response>
        </responses>
    </item>
    Here is the stylesheet.
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="html"
    		encoding="utf-8"
    		omit-xml-declaration="yes" />
    	<xsl:template match="/">
    			<p class="header1">SCO Test</p>
    			<p>
    			<xsl:apply-templates />
    			</p>
    	</xsl:template>
    	<xsl:template match="item"><span class="tooltip"><xsl:value-of select="itemId" /><span class="tooltip_text"><xsl:value-of select="instructions" /></span></span><br /></xsl:template>
    </xsl:stylesheet>
    Like I said, the transformation works with the plain XML file, but not with the PHP file.
    -- </byuhobbes>

  • #3
    Regular Coder byuhobbes85's Avatar
    Join Date
    Oct 2006
    Location
    Ames, Iowa, USA
    Posts
    116
    Thanks
    9
    Thanked 4 Times in 4 Posts
    I think I have a solution.

    If you want to execute PHP in your XML or XSL documents, take the following steps.
    • place the XML/XSL in a file with a PHP extension
    • place any XML tags that begin with <? into PHP echo statements so they are not mistaken by the PHP processor as PHP code
    • designate the mime-type using the PHP command below


    Here is how you designate the mime-type
    PHP Code:
    header("content-type: application/xhtml+xml; charset=utf-8"); 
    Hope this helps.
    -- </byuhobbes>

  • #4
    New Coder
    Join Date
    Nov 2008
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the response. I still couldn't get it working though. I think I have given up on executing PHP within an xml/xsl document. My focus now is learning how to pass the xml and xsl files through a PHP file, then echo out the result...

    Looks like I have some reading to do.

    Article on using PHP with XML and XSLT
    http://www.codewalkers.com/c/a/Misce...-XSLT-and-PHP/

    XSLT @ PHP.net
    http://us.php.net/manual/en/book.xslt.php

    xslt_process @ PHP.net
    http://us3.php.net/xslt_process

    Download Sablotron XML toolkit
    http://www.gingerall.org/sablotron.html

    Download Expat XML Parser
    http://expat.sourceforge.net/

    Article on using expat with PHP
    http://www.phpbuilder.com/columns/justin20000428.php3

  • #5
    New Coder
    Join Date
    Nov 2008
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have found a solution for my application.

    Now I just need an auto-sitemap generator so that it is updated for search engines and my site without me doing anything....??

    sitemap.php
    Code:
    <html>....
    <?php
    
       $xslDoc = new DOMDocument();
       $xslDoc->load("stylesheets/sitemap.xsl");
    
       $xmlDoc = new DOMDocument();
       $xmlDoc->load("sitemap.xml");
    
       $proc = new XSLTProcessor();
       $proc->importStylesheet($xslDoc);
       echo $proc->transformToXML($xmlDoc);
    ?>
    </html>
    sitemap.xsl
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns="http://www.w3.org/1999/xhtml">
    <xsl:template match="/">
    
        <table class="sitemap">
        <tr>
          <th align="left">URLs</th>
          <th align="left">Last Modified</th>
        </tr>
        
    	<xsl:for-each select="urlset/url">
        <tr>
    	<td>	
    	<xsl:element name="a">
    	<xsl:attribute name="href">
    	<xsl:value-of select="loc"/>
    	</xsl:attribute>
    	<xsl:value-of select="loc"/>
    	        </xsl:element>
    	</td>
    	<td><xsl:value-of select="lastmod"/></td>
        </tr>
        
    	</xsl:for-each>
        </table>
    
    </xsl:template>
    </xsl:stylesheet>
    sitemap.xml
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <urlset>
    	<url>
    		<loc>http://www.asdf.com/</loc>
    		<lastmod>2008-10-01</lastmod>
    </url>
    </urlset>

  • #6
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your solution ..

    I was looking at techniques for embedding php code in xhtml files using a technique like this .. for svg ..

    http://www.carto.net/papers/svg/samp..._svg_php.shtml


    this would require a new mime type to be created in Apache mime.types file .. let's call it

    .pxhtml .. similar to .psvg example

    In fact you could embed svg in an xform


    # ________________________________

    # added new type pxhtml .. embedding php in xhtml files
    # http://www.456bereastreet.com/archiv...html_properly/

    application/xhtml+xml xhtml xht pxhtml

    # ________________________________


    But it seems that your code might offer a neater solution ..


    also see here .. accepting XForms in PHP

    http://www.ibm.com/developerworks/xm...php/index.html

  • #7
    New Coder
    Join Date
    Nov 2008
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have found myself trying to execute PHP tags within an XSL file again. I was told in another forum that this will do it.

    In HTACCESS:

    AddHandler application/x-httpd-php5 .xsl

    It does not work for me.

    I would like to place a "php includes statement" for my menus.

    Code:
    <ul>
    <li><a href="/index.php?page=index">Home</a></li>
    <li><a href="/index.php?page=pricing">Pricing</a></li>
    <li><a href="/index.php?page=memos">Memos</a></li>
    <li><a href="/index.php?page=forms">Forms</a></li>
    <li><a href="/index.php?page=sales">Sales Support</a></li>	
    </ul>
    Code:
    <?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/menu.php'); ?>

    What am I missing here?

  • #8
    New Coder
    Join Date
    Nov 2008
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Looks like it is better to use the XSL include for this application.

    I am still looking for a solution to executing PHP in these templates??....BUMP!


    This is the file that needs to be included.
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:template name="menu">
    <ul>
    <li><a href="/index.php?page=index">Home</a></li>
    <li><a href="/index.php?page=pricing">Pricing</a></li>
    <li><a href="/index.php?page=memos">Memos</a></li>
    <li><a href="/index.php?page=forms">Forms</a></li>
    <li><a href="/index.php?page=sales">Sales Support</a></li>	
    </ul>
     </xsl:template>
    </xsl:stylesheet>

    File doing the including....
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns="http://www.w3.org/1999/xhtml">
    <xsl:include href="constant/mainTemplate.xsl" />
    <xsl:output method="xml" omit-xml-declaration = "yes" indent="yes"/>
    
    <xsl:template match="/">
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <xsl:call-template name="menu"/>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>


  •  

    Tags for this Thread

    Posting Permissions

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