Помогите распарсить XML при помощи XSLT

Николас

Новичок
если уже есть xslt, то смотри такое:
PHP:
<?php
$sourcefile = "xml file";
$stylesheetfile = "xsl file";
$xml = new DOMDocument();
$xml->load($sourcefile);
$xsl = new DOMDocument();
$xsl->load($stylesheetfile);
$xslt = new XsltProcessor();
$xslt-> importStylesheet ($xsl);
$result = $xslt->transformToDoc($xml);
echo $result->saveXML();
?>
 

jian

Новичок
Re: Помогите распарсить XML при помощи XSLT

Код:
<?xml version="1.0" encoding="windows-1251"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:output method="html" encoding="windows-1251" indent="yes" /> 

  <xsl:template match="/">
	<table border="1">
		<xsl:apply-templates select="table/row"/>
	</table>
  </xsl:template>

  <xsl:template match="row">
	<xsl:if test="col/@colspan">
		<xsl:call-template name="inner"/>
	</xsl:if>
  </xsl:template>

  <xsl:template match="col">
	<td>
		<xsl:value-of select="."/>
	</td>
  </xsl:template>

  <xsl:template name="inner">
	<xsl:param name="counter" select="1"/>
	<xsl:if test="col/@colspan > $counter">
		<xsl:variable name="num" select="$counter + position()"/>
		<tr>
			<td>
				<xsl:value-of select="."/>
			</td>
			<xsl:apply-templates select="../row[$num]/col"/>
		</tr>
		<xsl:call-template name="inner">
			<xsl:with-param name="counter" select="$counter + 1"/>
		</xsl:call-template>
	</xsl:if>
  </xsl:template>

</xsl:stylesheet>
 
Сверху