Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  yordan : (16 June 2013 - 05:41 PM) You're Welcome, Agyat!
@  agyat : (16 June 2013 - 07:38 AM) Thanks Yordan...
@  velma : (16 June 2013 - 12:06 AM) I Have Asked Opa To Check For A Backup.. He'll Let Me Know Soon :)
@  velma : (16 June 2013 - 12:05 AM) T_T It Seems That Someone Has Deleted That Topic Since I Found The Url Of The Topic But It Gives Me An Error
@  yordan : (15 June 2013 - 10:31 PM) @velma : It's A Tuto On How To Create A Login Program.
@  yordan : (15 June 2013 - 10:31 PM) Happy Birthday To Youuuuuu Agyat!
@  yordan : (15 June 2013 - 10:31 PM) Ba$
@  agyat : (15 June 2013 - 04:41 PM) :(
@  agyat : (15 June 2013 - 04:41 PM) Where The Hall I Were? 15Th Is Almost At End And No-One Wished Me "happy Birthday"!!!
@  velma : (14 June 2013 - 10:39 AM) Which Tutorial Is He Searching For?
@  velma : (14 June 2013 - 10:38 AM) Which Tutorial Is He Searching For?
@  yordan : (14 June 2013 - 07:47 AM) Ok, Have A Look Tomorrow.
@  yordan : (13 June 2013 - 03:19 PM) @velma, Can You Have A Look At Feelay's Problem? Seems That His Tutorial Is Not Searchable Today.
@  Feelay : (13 June 2013 - 08:11 AM) Oh, Haha
@  velma : (12 June 2013 - 05:39 PM) T_T Lately My Levels Of Procrastination..... **sigh**
@  velma : (12 June 2013 - 05:38 PM) I'll Do It Later
@  velma : (12 June 2013 - 05:38 PM) Procrastinators.. People Who Keep Saying "i'll Do This In A Bit"
@  Feelay : (12 June 2013 - 02:05 PM) Deal Punishments To What?
@  velma : (12 June 2013 - 01:27 PM) T_T We Should Deal Punishments To Procrastinators... Especially Me
@  Feelay : (12 June 2013 - 12:06 PM) As Well As Making It More Secure.

Replying to XSLT Beginner


Post Options

    • Can't make it out? Click here to generate a new image

  or Cancel


Topic Summary

FirefoxRocks

Posted 13 June 2008 - 03:28 AM

First of all, you do not need to use server side XSLT parsing to read an XML file. You can simply specify it as a stylesheet using an XML processing instruction in the XML file like this:
<?xml-stylesheet type="text/xsl" href="yourFile.xsl" ?>
.

Second of all, for a beginner tutorial, I wouldn't make it as complicated with attribute names and multiple templates. I mean <xsl:call-template />? That is definitely not for beginners.

Internet Explorer has the MSXML parser, Gecko-based browsers (Firefox/Mozilla/Flock) has a built-in XSLT parser and Safari/Konqueror can also read XSLT correctly too. You don't need PHP to parse XSLT, browsers can do it.

virtuous8

Posted 15 March 2006 - 06:31 AM

start with an xml file:

<?xml encoding="utf-8" version="1.0"?>

<root>
  <contact type="business">
	 <name>John</name>
  </contact>
  <contact type="business">
	 <name>Jane</name>
  </contact>
  <contact type="business">
	 <name>Jack</name>
  </contact>
  <contact type="family">
	 <name>Jim</name>
  </contact>
</root>


now write your contacts.xslt file:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" encoding="utf-8" />	
<xsl:template match="/">
  <html>
  <xsl:for-each select="//contact/[type=business]">
	<xsl:call-template name="contact" />
  </xsl:for-each>	
  </html>
</xsl:template>
	
<xsl:template name="family">
   <xsl:value-of select="./name" />
   <br/>
</xsl:template>

</xsl:stylesheet>


now you need xslt processor to combine xml + xslt, in php there is get Sablotron xslt processor.
example using Sablotron:

<?php
	$xmlFile = 'contacts.xml';
	$xslFile = 'contacts.xslt';
	// Create a new processor handle
	$xslt_processor= xslt_create() or die("Can't create XSLT processor handle!");
	//set up parameters
	//$parameters = array('searchstring'=>$searchstring);
	$parameters = NULL;
	//perform the XSLT transformation
	$result = xslt_process($xslt_processor, $xmlFile, $xslFile, NULL, NULL, $parameters);
	// Free up the resources
	xslt_free($xslt_processor);
	echo($result);
?>

the output is:
John
Jane
Jack


notes and explanation:
xslt uses powerful xpath expression to navigate through the xml parsetree.

Review the complete topic (launches new window)