Autor Zpráva
mar
Profil *
procetl jsme spousty manualu a stejnak my to nemohu rozchodit, pritom phpinfo() vraci:

DOM/XML enabled
libXML - active,enabled
XSL - enabled
libxslt - enabled

zde je kod,kt. chci xsl vyzkouset:




xml:

<?xml version="1.0" encoding="UTF-8"?>
<article>
<title>A Sample Article</title>
<section>
<title>Article Section 1</title>
<para>
This is the first section of the article. Nothing terribly
interesting here, though.
</para>
</section>
<section>
<title>Another Section</title>
<para>
Just so you can see how these things work, here's an
itemized list:
</para>
<itemizedlist>
<listitem>
<para>The first item in the list</para>
</listitem>
<listitem>
<para>The second item in the list</para>
</listitem>
<listitem>
<para>The third item in the list</para>
</listitem>
</itemizedlist>
</section>
</article>

xsl:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

<xsl:template match="article">
<html>
<head>
<title><xsl:value-of select="title"/></title>
</head>
<body>
<h1><xsl:value-of select="title"/></h1>
<xsl:apply-templates select="section"/>
</body>
</html>
</xsl:template>

<xsl:template match="section">
<xsl:apply-templates/>
<hr/>
</xsl:template>

<xsl:template match="section/title">
<h2><xsl:apply-templates/></h2>
</xsl:template>

<xsl:template match="para">
<p><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="itemizedlist">
<ul><xsl:apply-templates/></ul>
</xsl:template>

<xsl:template match="listitem">
<li><xsl:apply-templates/></li>
</xsl:template>
</xsl:stylesheet>

php:

<?php
// Create an XSLT processor
$xsltproc = xslt_create();

// Perform the transformation
$html = xslt_process($xsltproc, 'docbook.xml', 'docbook.xsl');

// Detect errors
if (!$html) die('XSLT processing error: '.xslt_error($xsltproc));

// Destroy the XSLT processor
xslt_free($xsltproc);

// Output the resulting HTML
echo $html;
?>



kde mam chybu?
mar
Profil *
aj..... tohle je zrejme postup pro php4.... asi sem na to kapnul... musim pouzit rozhrani DOMDocument...
mar
Profil *
Vyreseno:

1.php pouziva DOM/XML:
<?php
$doc = new DOMDocument();
$doc->load('docbook.xml');
echo $doc->saveXML();
?>

2.nemel sem sparovany xml s xsl sablonou pomoci:
<?xml-stylesheet media="screen" type="text/xsl" href="docbook.xsl"?>

haha.....
mar
Profil *
Tak pro uplnost

horni reseni vyplivne xml soubor v prohliyeci

toto reseni provede transformatci..... hihi:

<?php

$doc = new DOMDocument();
$xsl = new XSLTProcessor();

$doc->load("docbook.xsl");
$xsl->importStyleSheet($doc);

$doc->load("docbook.xml");
echo $xsl->transformToXML($doc);

?>
Toto téma je uzamčeno. Odpověď nelze zaslat.

0