Main Menu




browser lang:en

Users Area

Client Login

today cache size is:0

 

 


Comments

fg
16/04/2011 by fdg
Hi all
13/02/2011 by
John
24/07/2010 by John
better
16/04/2010 by bob
attached files not working !
05/11/2009 by Adnan
Tuvok
14/02/2009 by
Nice script
07/02/2009 by desaj
Other solutions
07/02/2009 by Mike

Read More »


RAPIDQ

Rapid-Q:The lost files
My old library where i have collected all the rapidq scripts and italian help


Today my pagerank is: Free Page Rank Tool
Upbooking - free booking engine

XSLT - pass a parameter inside XSL with PHP

Working in XSLT and PHP integration, one of the most necessary needs a developer necesitates, after XML-XSL integration, is how to pass variable or data inside the XSL script.
Why we necesite it? Well, for example if we do a dynamic Query (in this case XQuery) that use a Record (in this case one elemento of the XML tree), i mean the classic request (GET, POST o something else) but applied to the XSLT.

XML tree example: location.xml <CityLocations> <CityLocation> <CityID>1</CityID> <LocationName>New York</LocationName> </CityLocation> <CityLocation> <CityID>2</CityID> <LocationName>Chicago</LocationName> </CityLocation> </CityLocations>
Now we create the XSL file that execute the XQuery and receive the CityID parameter
Example:location.xsl.php

 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <table width="100%">
      <tr>
		<th>CityId</th>
        <th>LocationName</th>
      </tr>
      <xsl:for-each select="CityLocations/CityLocation[CityID=$CityID]">
      <tr>
        <td><xsl:value-of select="CityID"/></td>
        <td><xsl:value-of select="LocationName"/></td>
      </tr>
      </xsl:for-each>
    </table>
</xsl:template>
</xsl:stylesheet>

And at last we go to create the PHP file that integrates XML and XSL and injects the parameter inside the XSL
Example:location.php
 
 
// ------------Applica un file XSL a un XML In PHP 5  --------------------
$cityLocations = "1";
// Carica il file dati
 
$xml = new DOMDocument("1.0");
$xml->load($_SERVER['DOCUMENT_ROOT'].'/xml/location.xml');
 
// Carica il file stile
$xsl = new DOMDocument("1.0");
$xsl->load($_SERVER['DOCUMENT_ROOT'].'/xslt/location.xsl.php');
// Crea un processore XSLT
$proc = new XSLTProcessor;
// Setta un parametro da trasformare nel file XSL  
$proc->setParameter( '', 'CityID', $cityLocations);   
$proc->importStyleSheet($xsl); // Importa il file xslt
$dom=$proc->transformToDoc($xml);    // Output risultato a documento DOM
$dom->formatOutput=true;
echo  $dom->saveXML($dom->documentElement);  // Invia il risultato a un browser 


Final result will be : CityID:1

LocationName:New York

Surely we can use this kind of operation for more complex things.


Comments

Insert your comment

Titolo
Messaggio
Nome Utente
e-mail (se vuoi ricevere le risposte a questo post anche via mail)

Users

Videos


Scripts & Tutorials

50 necessaries php tools

25/02/2011 

PHP is one of the most widely used open-source server-side scripting languages that exist today. With over…

in:Scripts and tutorials (0 comments)

FBJS Quick Jump Menu for a FBML Facebook Platform App

15/07/2010 

In a FBML Facebook App, your quick jump menu will require a little tweak to work in FBJS…

in:Scripts and tutorials (0 comments)

How to manage your online reputation, free tools forcommunity managers

02/07/2010 

Every single day, someone, somewhere is discussing something important to your business; your brand, your executives, your…

in:Scripts and tutorials (0 comments)

PHP - The Singleton Pattern

26/11/2009 

The Singleton Pattern is one of the GoF (Gang of Four) Patterns. This particular pattern provides a…

in:Scripts and tutorials (0 comments)

PHP - calculating distance between two points

20/10/2009 

Because of the near-spherical shape of the Earth, calculating an accurate distance between two points requires the use…

in:Scripts and tutorials (1 comments)

PHP - Download file with speed limit

20/10/2009 

With this script we can limit the download speed   // local file that should be send to the client $local_file…

in:Scripts and tutorials (0 comments)

PHP - Save remote images on our server using CURL

12/10/2009 

Some hosts disabled the ini setting allow_url_fopen. This also means that the ability to easily grab images…

in:Scripts and tutorials (0 comments)

PHP - verify file existence in a local server

11/06/2009 

The act to verify if a file exists, is one of more important tasks related to files operations,…

in:Scripts and tutorials (0 comments)

Read more »


Tag Clouds


necessaries toolsFBJS Quick Jump Menu FBML Facebook Platform AppHow manage your online reputation free tools forcommunity managersPHP Singleton PatternPHP calculating distance between points Download file speed limitPHP Save remote images


Add to Technorati Favorites