Portál AbcLinuxu, 30. dubna 2025 21:23
Jeliko je redakcnich systemu nedostatek (ironie), rozhodl jsem se vytvorit dalsi. Na vystupu generuje XML, ktere by se melo pomoci XSLT transformace transformovat na XHTML. Až na to, že to nefunguje
Výstup systému vypadá přibližně takhle:
<?xml version="1.0" encoding="UTF-8"?> <page xmlns="default" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="default schema.xsd"> <menu> <name id_menu="1">menu_1</name> <name id_menu="2">menu_2</name> <name id_menu="3">menu_3</name> </menu> <content> <path id_menu="1">menu_1</path> <name id_text="">TEST 1</name> <autor id="1">Lukas Jirkovsky</autor> <perex>vaelrbvoabraebuo viubaeivb</perex> </content> </page>
Tento výstup se má transformovat pomocí takovéto šablony:
<?xml version='1.0'?> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'> <xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" indent="yes"/> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="style.css" /> <title>Testovaci stranka</title> </head> <body> <div id="baseborder"> <div id="top"> TOP </div> <xsl:apply-templates select="menu|content"/> </div> </body> </html> </xsl:template> <xsl:template match="menu"> <div id="menu"> <xsl:apply-templates select="name" mode="menu"/> </div> </xsl:template> <xsl:template match="name" mode="menu"> <a href="index.php?id_menu={@id_menu}"><xsl:value-of select="."/></a> </xsl:template> <xsl:template match="content"> <div id="obsah"> <xsl:apply-templates select="path|name|autor|perex|text"/> </div> </xsl:template> <xsl:template match="path"> <a href="index.php?id_menu={@id_menu}" class="path"><xsl:value-of select="."/></a> <a href="index.php?id_menu={@id_menu}&id_text={@id_text}" class="path"><xsl:value-of select="."/></a> </xsl:template> </xsl:stylesheet>
Na výsledku vyleze toto:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="style.css"></link> <title>Testovaci stranka</title> </head> <body> <div id="baseborder"><div id="top"> TOP <!-- CHYBA, TADY BY MELY BYT JESTE VECI Z MENU A CONTENT --> </div> </div> </body> </html>Jsem blbej já nebo co, když nikde nevidím chybu a přesto to na výlezu jaksi ignoruje <xsl:template match="menu"> a <xsl:template match="content"> Na ostatní se samozřejmě ani nedostane. Neví někdo, kde je chyba?
PS: Dotaz už jsem napsal na diskuse.jakpsatweb.cz, zatím ale bez odpovědi.
Tiskni
Sdílej:
<xsl:apply-templates select="page">
a pridat
<xsl:template match="page"> TEST </xsl:template>Presto se nic nezmenilo :-| Dělá to procesor Firefoxu 1.5.0.7, Opery 9.02 i xsltproc z libxslt 1.1.17
<?php $xslt = new xsltProcessor; $xsl=DomDocument::load('neco.xsl'); $xslt->importStyleSheet($xsl); $fd = fopen("neco.xml", 'r'); $xmlString = fread($fd, filesize("neco.xml")); fclose($fd); $xml = DomDocument::loadXML($xmlString); print $xslt->transformToXML($xml); ?>
[tsunami@vodik]$ php -version PHP 5.1.6 (cli) (built: Aug 29 2006 13:30:12) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
[tsunami@vodik]$ cat neco.xsl <xsl:template match="/page"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" /> <title>Testovaci stranka</title> </head> <body> <div id="baseborder"> <div id="top"> TOP </div> <xsl:apply-templates select="menu"/> </div> </body> </html> </xsl:template> <xsl:template match="menu"> <div id="menu"> <xsl:apply-templates select="name" mode="menu"/> </div> </xsl:template> <xsl:template match="name" mode="menu"> <a href="index.php?id_menu={@id_menu}"><xsl:value-of select="."/></a> </xsl:template> </xsl:stylesheet>
[tsunami@vodik]$ cat neco.xsl <?xml version="1.0" encoding="UTF-8"?> <page> <menu> <name id_menu="1">menu_1</name> <name id_menu="2">menu_2</name> <name id_menu="3">menu_3</name> neco </menu> <content> <path id_menu="1">menu_1</path> <name id_text="">TEST 1</name> <autor id="1">Lukas Jirkovsky</autor> <perex>vaelrbvoabraebuo viubaeivb</perex> </content> </page>
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf8"> <title>Testovaci stranka</title></head><body><div id="baseborder"><div id="top"> TOP </div><div xmlns="" id="menu"> <a href="index.php?id_menu=1">menu_1</a><a href="index.php?id_menu=2">menu_2</a><a href="index.php?id_menu=3">menu_3</a> </div></div></body></html>
<page xmlns="default" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="default schema.xsd">
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="schema.xsd">
page/menu
a page/content
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.