XSLT (PHP 4) Функции
Содержание
- xslt_backend_info — Возвращает информацию о настройках, заданных при компиляции расширения (backend)
- xslt_backend_name — Возвращает имя расширения
- xslt_backend_version — Возвращает номер версии Sablotron
- xslt_create — Создает новый XSLT-процессор
- xslt_errno — Возвращает код ошибки
- xslt_error — Возвращает сообщение об ошибке
- xslt_free — Освобождение XSLT-процессора
- xslt_getopt — Получение настроек заданного XSLT-процессора
- xslt_process — Запуск XSLT преобразования
- xslt_set_base — Установка базового URI для всех XSLT преобразований
- xslt_set_encoding — Задание кодировки для разбора XML документов
- xslt_set_error_handler — Задание обработчика ошибок для XSLT-процессора
- xslt_set_log — Задание файла журнала для записи сообщений XSLT процессора
- xslt_set_object — Задает объект, в котором будут реализованы callback-функции
- xslt_set_sax_handler — Задает SAX обработчик для XSLT-процессора
- xslt_set_sax_handlers — Задает SAX обработчики, которые будут вызваться после разбора XML докумнента
- xslt_set_scheme_handler — Задает обработчики схемы для XSLT-процессора
- xslt_set_scheme_handlers — Задает обработчики схемы для XSLT-процессора
- xslt_setopt — Установка значений настроек XSLT-процессора
[an error occurred while processing the directive]
Коментарии
Building Sablotron on Solaris with.
gcc 3.0.3 and native linker
libtool (sunfreeware)
apache 1.3.24
php-4.2.1
sablotron-0.90
expat-1.95.2
When configuring Apache you might experience this error..
libsablot.so: undefined reference to `operator new[](unsigned)'
libsablot.so: undefined reference to `__cxa_call_unexpected'
libsablot.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
libsablot.so: undefined reference to `operator delete(void*)'
libsablot.so: undefined reference to `__gxx_personality_v0'
libsablot.so: undefined reference to `vtable for __cxxabiv1::__class_type_info'
libsablot.so: undefined reference to `operator delete[](void*)'
libsablot.so: undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
libsablot.so: undefined reference to `operator new(unsigned)'
To cure it make sure that during the configure stage you feed configure LDFLAGS variable like so.
LDFLAGS=' -lstdc++' ./configure
Otherwise Apache's compiler sanity check will balk.
In addition to "tk dot lists at fastmail dot fm"'s comment on Windows dependencies: You'll also need iconv.dll in your SYSTEM32 folder. At least, that's what I needed to get it working on my PHP4.2.3-Win install.
If you get problems with undefined references to gxx_s type stuff, UPDATE LIBTOOL! I found 1.4.1 worked for some configurations, 1.4.3 worked for almost none, but 1.5 worked for every combination of Sablotron/gettext/sybase/zlib/postgres --with options I tried.
Make sure you follow the advice of adding -lstdc++ to EXTRA_LD_FLAGS in Makefile after you've run ./configure, and BEFORE you've run make (if you issue make, you'll need to do a make clean before you make again, after changing the Makefile, or it still won't work reliably).
Cheers, Dave.
Another way to get around the EXPAT-SABLOTRON problems (seg faults) is supposedly to recompile apache with:
--disable-rule=EXPAT
As an update to the previous advice about the undefined references problem when installing PHP with Sablotron, PHP 4.3.4 has a new EXTRA_LDFLAGS_PROGRAM line added to the Makefile. Make sure to add -lstdc++ to this line as well as the EXTRA_LDFLAGS line.
bat at flurf, you said that Sablotron implements XSLT 1.1, but according to its makers, "Sablotron is ...implementing XSLT 1.0, DOM Level2 and XPath 1.0" [http://www.gingerall.org/sablotron.html]
The XSLTProcessor, when transforming a document, always resolves entities.
To avoid this (if you want to keep HTML entitities by ex.), you have two solutions:
- if you have full control over the input document, you can encapsulate every text element which contains entities in a CDATA section.
- the previous solution is the smarter and the less computing intensive, but it is not always possible. In other cases, what you can do is to replace every occurence of '&' (entity mark) by something which will be considered as normal text by the parser (let's say '[AMP]' by ex) in the input document before the transformation. After the transformation, you can get these entitites back in the output document by reversing the previous operation.
<?php
$xml = $input_dom->saveXML();
$xml = str_replace('&', '[AMP]', $xml);
$input_dom->loadXML($xml);
$xml = $xsl->transformToXML($input_dom);
$xml = str_replace('[AMP]', '&', $xml);
$output_dom->loadXML($xml);
?>
Warning : this second method "escapes" ALL entities, even those you wouldn't want to be escaped. This is a raw explanation, fine-tune it to your own situation.
In addition to the contibution of "tom at kornack dot com" about converting an Apple plist (iPhoto or iTunes library or other) into a more general XML format, I have tried to simplify his xsl file a little further:
<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="no"/>
<!-- XSL file based on example on php.net by tom@kornack.com -->
<xsl:template match="dict">
<xsl:for-each select="key">
<xsl:variable name="n1" select="translate(.,' ','_')"/>
<xsl:variable name="pName"><xsl:choose>
<xsl:when test="string(number($n1))='NaN'">
<xsl:value-of select="$n1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('_',$n1,'_')"/>
</xsl:otherwise>
</xsl:choose></xsl:variable>
<xsl:element name="{$pName}">
<xsl:apply-templates select="following-sibling::*[1]"/>
</xsl:element>
</xsl:for-each>
</xsl:template>
<xsl:template match="array">
<xsl:for-each select="*"><xsl:element name="item">
<xsl:attribute name="nr"><xsl:number/></xsl:attribute>
<xsl:apply-templates select="."/>
</xsl:element></xsl:for-each>
</xsl:template>
<xsl:template match="string|integer|real|date|data">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="true|false">
<xsl:value-of select="name()"/>
</xsl:template>
<xsl:template match="text()|@*">
</xsl:template>
</xsl:transform>
How to make a XSLT Side with function
<code>
<xsl:output method="xhtml"/>
<xsl:template match="/">
<html>
<head><title>Ausgabe</title></head>
<body>
<xsl:apply-templates select="aktien/aktie"></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="aktie">
<xsl:if test="@isin">
<xsl:value-of select="name" />
<xsl:value-of select="fn:format-number(fn:sum(kurse/kurs/ausgabepreis) div fn:count(kurse/kurs), '##.00')" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
</code>