CODE
<?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>
<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:
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="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>
<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:
CODE
<?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);
?>
$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.

