Toon posts:

[XSL] include werkt niet (Sablotron)

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hallo allemaal,

Ik ben bezig met XSL/Sablotron (PHP) alles gaat goed. Maar in iedere xsl-file staat het volgende stukje:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<xsl:template match="STRONG">
    <STRONG>
        <xsl:apply-templates/>
    </STRONG>
</xsl:template>

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

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

Nu wilde ik dit stukje steeds includen. maar dat gaat niet goed:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?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" indent="yes" encoding="utf-8"/>

    <xsl:template match="Pagina">
        <HTML>
            <HEAD>
                <TITLE>
                    <xsl:value-of select="Titel"/>
                </TITLE>
                <LINK REL="stylesheet" HREF="../style.css" TYPE="text/css"/>
            </HEAD>
            <BODY>
                <xsl:apply-templates select="Tekst"/>
            </BODY>
        </HTML>
    </xsl:template>
    
    <xsl:include href="html.xsl"/>   
</xsl:stylesheet>

Als ik dit uitvoer krijg ik deze foutmelding:

Fatal error: 'arg:/html.xsl' not found in c:\phpdev\www\ube\class\class.xslt.php on line 40

Op line 40 staat de xslt_process functie.

Weet iemand wat ik fout doe? Dit is overigens de directory structuur:

- root
- - class
- - + class.xslt.php
- - xsl
- - + html.xsl
- - + pagina.xsl

Het bestandje html.xsl staat overigens in bijna ieder map. op dat ik dacht dat het eerst hier aan lag.

Al vast bedankt

  • marcusk
  • Registratie: Februari 2001
  • Laatst online: 26-09-2023
volgens mij moet je xslt_set_base gebruiken om de 'base URI' in te stellen, voordat je xslt_process aanroept.

zie ook de User Contributed Notes
op http://www.php.net/manual/en/function.xslt-process.php.

  • LuCarD
  • Registratie: Januari 2000
  • Niet online

LuCarD

Certified BUFH

Misschien is het ook handig de versie van PHP erbij te zetten aangezien 4.0.6 en 4.1.x een wereld van verschil zijn.

Moet je misschien een volledig path opgeven?

Hoe ziet jouw xslt_process eruit?

Programmer - an organism that turns coffee into software.


  • TheMrH
  • Registratie: April 2000
  • Laatst online: 01-09 22:45
Mmm, dit probleem had ik ook ooit. Toen heb ik me maar meer in de info vediept, beetje in de source gebrowsed van Sablotron enzow. Uiteindelijk heb ik alles maar in een mooi classje gepropt. Die werk nu lekker transparant, als het goed is op 4.0.6 en op 4.1.1.

Ik zet hem maandag wel ff online als er vraag naar is, hij is nl niet available hiero, wel op me werk...

The box said 'requires Windows 95 or better', so I installed Linux...


Verwijderd

Topicstarter
Bedankt, maar ik ben er nog niet uit. Ik werk met PHP 4.0.6. Als ik de xslt_set_base functie gebruik loopt apache vast. Dit is mijn code:
PHP:
1
<?class xslt{        var $sid;    var $xslt;        function xslt($sid)     {        $this->sid = $sid;        $this->xslt = xslt_create();        xslt_set_base($this->xslt, "file://c:/phpdev/www/ube/");    }        function paginas ($file_name)    {        $xml = join("", file("$file_name.xml"));        $xsl = join("", file("../xsl/pagina.xsl"));        xslt_process($xsl, $xml, $result);        $fp = fopen ("$file_name.html", "w+");        fwrite($fp, $result);        fclose($fp);    }}?>

Ik nu eerst maar eens updaten naar php 4.1.2 en verder wacht ik tot maandag op de class van TheMrH.

  • TheMrH
  • Registratie: April 2000
  • Laatst online: 01-09 22:45
Je kan/moet ook es proberen sablot van de commandline aanroepen. Die kan je hier http://download-2.gingerall.cz/download/sablot/Sablot-Win-0.82-FullPack.zip downloaden. Heel handig om je XSL sheets te testen.

Daarbij moet je eens proberen php.exe vanaf de commandline aan te roepen, dan zie je dus je output van je script, en ook meteen waar hij ermee kapt. Op deze manier heb ik ook wat bugjes in m'n nog 4.0.6 scriptje kunnen omgooien naar 4.1.1.

Ik zie in je script dat je xslt_set_base wilt gebruiken? Die zat er nog niet in in 406, wel in 411. Uit m'n hoofd kan de de base opgeven als 4e param aan xslt_process().

Good luck!

The box said 'requires Windows 95 or better', so I installed Linux...


  • brammetje
  • Registratie: Oktober 2000
  • Laatst online: 12-01-2025
dit werkt bij mij perfect, 4.1.1 en 4.0.6:
code:
1
    <xsl:include href="file://h:/webroot/javahova/xsl/_main/html/javahova_layout.xsl" />

volledig pad opgeven dus :)

  • Rense Klinkenberg
  • Registratie: November 2000
  • Laatst online: 09-08 19:19
als je straks ge-update heb naat 4.1.0 (of in ider geval de xslt extensie dan), kan je ook eens gaan proberen om de extra xsl als extra argument mee te geven.

Normaal gesproken geen je in php 4.1.0+ de xml en xsl al mee als argument aan sabletron. Op zich zou je ook extra argumenten aan in die array kunnen stoppen, die je dan aan zou kunnen roepen.

Aan de hand van de error die je kreeg, zou je dan de syntax wel kunnen afleiden:
code:
1
Fatal error: 'arg:/html.xsl' not found in c:\phpdev\www\ube\class\class.xslt.php on line 40

nu moet ik eerlijk zeggen dat ik er nog nooit mee getest heb, maar als je in de argumenten array een extra entry maakt, genaamd 'arg:/html', zou je die waarschijnlijk kunnen includen door
code:
1
<xsl:include href="html" />

  • TheMrH
  • Registratie: April 2000
  • Laatst online: 01-09 22:45
edit:
hier stond onzin


Dan moet hij volgens mij wel als <xsl:param name="html"/> gedeclareerd zijn in je stylesheet.

The box said 'requires Windows 95 or better', so I installed Linux...


  • TheMrH
  • Registratie: April 2000
  • Laatst online: 01-09 22:45
Zow, ff die class geupped op me website. Hier kan je hem vinden: http://www.themrh.com/stuff/class.XSLTransformer.phps

Als je nog op- en/of aanmerkingen hebt, graag!

The box said 'requires Windows 95 or better', so I installed Linux...


Verwijderd

Topicstarter
Ik kom er helaas nog niet uit, kan iemand mij een voorbeeld geven hoe ik de class van TheMrH kan toepassen in mijn situatie (zie boven). Ik heb overigens nog steeds PHP 4.0.6. Al vast heel erg bedankt

  • TheMrH
  • Registratie: April 2000
  • Laatst online: 01-09 22:45
PHP:
1
<?    // I'd use $base = dirname(__FILE__)    $base = '/basedir/for/xsl/files/';    require_once('class.XSLTransformer.php');    // Create a new instance with debugging enabled    $x = new XSLTransformer(true);        // Set the base URI path. You can play  with the    // file locations a bit to see what works for you    $x->setBaseUri($base);        // You could load the xsl as string, but why should we?     // Let's save some memory and processing power     //    // Else we'd do $x->setXsl($xslstring)     $x->setXslUri('path/to/file.xsl');        // Same comment as above...    $x->setXmlUri('path/to/file.xml');        // Perform the actual transformation    $x->transform();        // Did we raise an error?    if ($x->getErrorNo() == 0)    {        echo $x->getOutput();    }    else    {        echo $x->getErrorMsg();    }        // Clean up    $x->destroy();?>

Zoiets? I kzal het meteen als commentaar bovenin de code zetten...

The box said 'requires Windows 95 or better', so I installed Linux...


  • TheMrH
  • Registratie: April 2000
  • Laatst online: 01-09 22:45
Is het al gelukt?

The box said 'requires Windows 95 or better', so I installed Linux...

Pagina: 1