CXX. XSL functions

бБЕДЕМХЕ

Внимание

щРН ПЮЯЬХПЕМХЕ ЪБКЪЕРЯЪ щйяоепхлемрюкэмшл. оНБЕДЕМХЕ ЩРНЦН ПЮЯЬХПЕМХЪ, БЙКЧВЮЪ ХЛЕМЮ ЕЦН ТСМЙЖХИ Х НРМНЯЪЫСЧЯЪ Й МЕЛС ДНЙСЛЕМРЮЖХЧ, ЛНФЕР ХГЛЕМХРЭЯЪ Б ОНЯКЕДСЧЫХУ БЕПЯХЪУ PHP АЕГ СБЕДНЛКЕМХЪ. хЯОНКЭГСИРЕ ЩРН ПЮЯЬХПЕМХЕ МЮ ЯБНИ ЯРПЮУ Х ПХЯЙ.

The XSL extension implements the XSL standard, performing XSLT transformations using the libxslt library.

сЯРЮМНБЙЮ

PHP 5 includes the XSL extension by default and it can be enabled by adding the argument --with-xsl[=DIR] to your configure line. DIR is the libxslt installation directory. libxslt version 1.0.18 or greater is required.

оПХЛЕПШ

In this small tutorial we will learn how to transform an XML document into HTML.

Пример 1. A simple XSL tree

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" encoding="iso-8859-1" indent="no"/>
 <xsl:template match="collection">
  Hey! Welcome to my sweet CD collection!
  <xsl:apply-templates/>
 </xsl:template>
 <xsl:template match="cd">
  <h1><xsl:value-of select="title"/></h1>
  <h2>by <xsl:value-of select="artist"/></h2>
  <h3> - <xsl:value-of select="year"/></h3>
 </xsl:template>
</xsl:stylesheet>

Пример 2. Corresponding XML tree

<collection>
 <cd>
  <title>PHP Rock</title>
  <artist>Joe Coder</artist>
  <year>2003</year>
 </cd>
 <cd>
  <title>Squashing Typos on a Winter's Eve</title>
  <artist>kennyt</artist>
  <year>2004</year>
 </cd>
</collection>

Пример 3. Making XML into HTML

The following PHP code uses the XML and XSL extensions to transform XML into presentable HTML.

<?php
/* Load the two XML sources */
$xml = new DomDocument; // from /ext/dom
$xml->load('example.xml');

$xsl = new DomDocument;
$xsl->load('example.xsl');

/* Configure the transformer */
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
echo $proc->transformToXML($xml); // actual transformation
?>

This should produce an HTML fragment similar to the following:

Hey! Welcome to my sweet CD collection!

<h1>PHP Rock</h1>
<h2>by Joe Coder</h2>
<h3> - 2003</h3>

<h1>Squashing Typos on a Winter's Eve</h1>
<h2> by kennyt</h2>
<h3> - 2004</h3>


HIVE: All information for read only. Please respect copyright!
Hosted by hive йца: йХЕБЯЙЮЪ ЦНПНДЯЙЮЪ АХАКХНРЕЙЮ