Location: PHPKode > scripts > DOM Class > dom-class/DOMClass.php
<?
class DOMClass
{
	var $PathSeparator;
	var $CurrentDir;
	var $XmlDocument;
	var $XmlFile;
	var $XslFile;
	var $CodeXsl =
	'<?xml version="1.0" encoding="ISO-8859-1"?>
		<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		<xsl:output method="xml" indent="yes"/> 
		<xsl:strip-space elements="*"/> 
		<xsl:template match="/"> 
		  <xsl:copy-of select="."/> 
		</xsl:template> 
		</xsl:stylesheet>';
	
	function DOMClass()
	{
		 $this->CurrentDir = getcwd();
		 $this->PathSeparator = DIRECTORY_SEPARATOR;
	}
	
	function ShowXsl()
	{
		$xsldoc = domxml_xslt_stylesheet($this->CodeXsl);
		$tmpXmlDocument = domxml_open_file($this->CurrentDir .$this->PathSeparator. $this->XslFile);
		$result =  $xsldoc->process($tmpXmlDocument);
	
		if ($result) {
			print "<h2>Archivo XSLT: $this->XslFile</h2><br/>";
		    	print "<pre>\n";
		    	print htmlentities($xsldoc->result_dump_mem($result));
		    	//print htmlentities(utf8_decode($result));
		    	print "</pre>\n";
			print "<hr size='1'/>";
		}
	}

	function ShowXml()
	{
		$xsldoc = domxml_xslt_stylesheet($this->CodeXsl);
		$result =  $xsldoc->process($this->XmlDocument);
	
		if ($result) {
			print "<h2>Archivo XML</h2><br/>";
		    	print "<pre>\n";
		    	print htmlentities($xsldoc->result_dump_mem($result));
		    	//print htmlentities(utf8_decode($result));
		    	print "</pre>\n";
			print "<hr size='1'/>";
		}
	}

	function Transform($ShowXml=false, $ShowXSL=false)
	{
		if ( !isset($this->XmlDocument) )
		{
			die("Especifique un documento XML antes de procesar");
		}
		else if ( !isset($this->XslFile) )
		{
			die("Especifique un archivo XSLT antes de procesar");
		}
		if ( $ShowXml )
		{
			$this->ShowXml();
		}
		if ( $ShowXSL )
		{
			$this->ShowXsl();
		}
		$xsldoc = domxml_xslt_stylesheet_file($this->CurrentDir . $this->PathSeparator. $this->XslFile);
		$result =  $xsldoc->process($this->XmlDocument);
	
		if ($result) {
		    	//print utf8_decode($xsldoc->result_dump_mem($result));
		    	print $xsldoc->result_dump_mem($result);
		}
	}
	function TransformFromXmlFile($ShowXml=false, $ShowXSL=false)
	{
		if ( !isset($this->XmlFile) )
		{
			die("Especifique un archivo XML antes de procesar");
		}
		else if ( !isset($this->XslFile) )
		{
			die("Especifique un archivo XSLT antes de procesar");
		}
		if (!$this->XmlDocument = domxml_open_file($this->CurrentDir . $this->PathSeparator. $this->XmlFile)) {
		  	echo "Error al tratar de cargar el archivo XML";
  			exit;
		}
		if ( $ShowXml )
		{
			$this->ShowXml();
		}
		if ( $ShowXSL )
		{
			$this->ShowXsl();
		}
		$xsldoc = domxml_xslt_stylesheet_file($this->CurrentDir . $this->PathSeparator. $this->XslFile);
		$result =  $xsldoc->process($this->XmlDocument);
	
		if ($result) {
		    	print utf8_decode($xsldoc->result_dump_mem($result));
		//    	print $xsldoc->result_dump_mem($result);
		}
	}
}
	
?>
Return current item: DOM Class