CATEGORII DOCUMENTE |
Este
ilustrat modul de utilizare a limbajului XSLT in partea de server a aplicatiilor
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="pictori.xsl" type="text/xsl"?>
<catalog>
<pictor>
<nume>Paul Gauguin</nume>
<curent>postimpresionism</curent>
<pictura an="1891">
<!-- Numele unei picture representative -->
Tahitian Women
</pictura>
</pictor>
<pictor>
<nume>Vincent van Gogh</nume>
<curent>postimpresionism</curent>
<pictura an="1889">
Starry Night
</pictura>
</pictor>
<pictor>
<nume>Henri Matisse</nume>
<curent>impresionism</curent>
<pictura an="1906">
Self-Portrait in a Striped T-Shirt
</pictura>
</pictor>
</catalog>
Continutul fisierului pictoriXSLT.xsl este urmatorul:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="https://www.w3.org/1999/XSL/Transform">
<xsl:template match="/catalog">
<html xmlns="https://www.w3.org/1999/xhtml">
<body>
<center><h2>Pictori, curente si picturi</h2></center>
<table align="center" cellspacing="2"
cellpadding="5" border="1">
<tr>
<th>Nume</th>
<th>Curent</th>
<th>Pictura</th>
</tr>
<xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="pictor">
<tr>
<td><xsl:value-of select="nume"/></td>
<td><xsl:value-of select="curent"/></td>
<td><xsl:apply-templates select="pictura"/></td>
</tr>
</xsl:template>
<xsl:template match="pictura">
<xsl:value-of select="."/>
<xsl:apply-templates select="@an"/>
</xsl:template>
<xsl:template match="@an">
(<i><xsl:value-of select="."/></i>)
</xsl:template>
</xsl:stylesheet>
Aplicatia
afiseazaPictori contine alaturi de pictori.xml si pictoriXSLT.xsl fisierele pictori.html,
functii.js si pictori.php. Fisierele amintite vor fi incluse in subdirectorul afiseazaPictori al directorului
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>Pictori</title>
<script src="functii.js" type="text/javascript"></script>
</head>
<body>
<center>
<h3>Pictori</h3>
<form name="formular">
<input type="button" onclick="afiseazaPictori()"
value="Afiseaza" />
<input type="button" onclick="ascundeDiv('mesaj')"
value="Ascunde" />
</form>
<div id="mesaj"
style="width: 500px; color: blue; padding: 5px;
background-color: #E6E6E6;
border: 1px solid gray; visibility: hidden">
</div>
</center>
</body>
</html>
Fisierul functii.js contine definitiile functiilor JavaScript utilizate in aplicatie: afiseazaPictori() trateazaCererea( arataDiv() si ascundeDiv(). In continuare sunt prezentate definitiile primelor doua functii:
// Functia de trimitere a cererii asincrone catre server
var cerere;
function afiseazaPictori()
// Functia pentru tratarea evenimentelor de transmisie asincrona
function trateazaCererea()
else
Fisierul pictori.php prin a carui executie este generat raspunsul trimis clientului de catre server are urmatorul continut:
<?php
// Este incarcat documentul XML
$xml = new DOMDocument;
$xml->load('pictori.xml');
// Este incarcat documentul XSL
$xsl = new DOMDocument;
$xsl->load('pictoriXSLT.xsl');
// Se creeaza un procesor
$procesor = new XSLTProcessor;
// Se includ regulile xsl definite in pictori_transf.xsl
$procesor->importStyleSheet($xsl);
// Se realizeaza transformarea XSLT si se afiseaza rezultatul
echo $procesor->transformToXML($xml);
?>
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 1065
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved