mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 07:02:08 +01:00
167 lines
4.4 KiB
XML
167 lines
4.4 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 10b60deaa2e4353299a66e99eae0f06d53ddb661 Maintainer: takagi Status: ready -->
|
|
<!-- CREDITS: hirokawa,shimooka -->
|
|
|
|
<chapter xml:id="xsl.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
&reftitle.examples;
|
|
<section xml:id="xsl.examples-collection">
|
|
<title>collection.xml および collection.xsl ファイルの例</title>
|
|
<para>
|
|
このリファレンスにある多くの例は、XML ファイルと XSL
|
|
ファイルの両方が必要です。
|
|
例では、以下の内容を含む <filename>collection.xml</filename> と
|
|
<filename>collection.xsl</filename> を使用します。
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>collection.xml</title>
|
|
<programlisting role="xml">
|
|
<![CDATA[
|
|
<collection>
|
|
<cd>
|
|
<title>Fight for your mind</title>
|
|
<artist>Ben Harper</artist>
|
|
<year>1995</year>
|
|
</cd>
|
|
<cd>
|
|
<title>Electric Ladyland</title>
|
|
<artist>Jimi Hendrix</artist>
|
|
<year>1997</year>
|
|
</cd>
|
|
</collection>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title>collection.xsl</title>
|
|
<programlisting role="xml">
|
|
<![CDATA[
|
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
<xsl:param name="owner" select="'Nicolas Eliaszewicz'"/>
|
|
<xsl:output method="html" encoding="iso-8859-1" indent="no"/>
|
|
<xsl:template match="collection">
|
|
Hey! Welcome to <xsl:value-of select="$owner"/>'s 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"/> - <xsl:value-of select="year"/></h2>
|
|
<hr />
|
|
</xsl:template>
|
|
</xsl:stylesheet>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</section>
|
|
|
|
<section xml:id="xsl.examples-errors">
|
|
<title>libxml のエラー処理関数によるエラー処理</title>
|
|
<para>
|
|
libxml にはエラー処理用の関数が用意されており、これらを使うと、
|
|
XSLT の処理中のエラーを捕らえて対応できます。
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>fruits.xml</title>
|
|
<para>妥当な XML ファイルです。</para>
|
|
<programlisting role="xml">
|
|
<![CDATA[
|
|
<fruits>
|
|
<fruit>Apple</fruit>
|
|
<fruit>Banana</fruit>
|
|
<fruit>Cherry</fruit>
|
|
</fruits>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title>fruits.xsl</title>
|
|
<para>無効な select 式が含まれています。</para>
|
|
<programlisting role="xml">
|
|
<![CDATA[
|
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
<xsl:output method="html" encoding="utf-8" indent="no"/>
|
|
<xsl:template match="fruits">
|
|
<ul>
|
|
<xsl:apply-templates/>
|
|
</ul>
|
|
</xsl:template>
|
|
<xsl:template match="fruit">
|
|
<li><xsl:value-of select="THIS IS A DELIBERATE ERROR!"/></li>
|
|
</xsl:template>
|
|
</xsl:stylesheet>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example xml:id="xsl.examples-errors.capture">
|
|
<title>エラーの捕捉と表示</title>
|
|
<para>
|
|
以下の例は、エラーを含むスタイルシートで
|
|
<methodname>XSLTProcessor::importStyleSheet</methodname>
|
|
を呼んだ際に発生する libxml のエラーを捕らえて表示するものです。
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$xmldoc = new DOMDocument();
|
|
$xsldoc = new DOMDocument();
|
|
$xsl = new XSLTProcessor();
|
|
|
|
$xmldoc->loadXML('fruits.xml');
|
|
$xsldoc->loadXML('fruits.xsl');
|
|
|
|
libxml_use_internal_errors(true);
|
|
$result = $xsl->importStyleSheet($xsldoc);
|
|
if (!$result) {
|
|
foreach (libxml_get_errors() as $error) {
|
|
echo "Libxml error: {$error->message}\n";
|
|
}
|
|
}
|
|
libxml_use_internal_errors(false);
|
|
|
|
if ($result) {
|
|
echo $xsl->transformToXML($xmldoc);
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Libxml error: Invalid expression
|
|
|
|
Libxml error: compilation error: file fruits.xsl line 9 element value-of
|
|
Libxml error: xsl:value-of : could not compile select expression 'THIS IS A DELIBERATE ERROR!'
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</section>
|
|
|
|
</chapter>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|
|
|