fishScript.com d
Home| Progetto| Web| Faq| Acronimi

Argomenti

Documenti pubblicabili:1120
Scripts:1282
Documenti non pubblicabili:162
Categorie tematiche:68
.Net
   |_C#
   |_Visual basic.net
   |_Asp.net
Active Server Pages
C++
Cascade Style Sheet
JavaScript
Mysql
Php
Xml
Java
   |_Java 2 Micro Edition
   |_Java server pages
   |_Java Servlet
Oracle
   |_PLSQL
PostgreSQL
Unix






A User Agent, like a web browser, uses HTTP to request a HTML document



In programming the danger of exploring the small details of coding is that you get obsessed with every line of code you write, thereby greatly reducing productivity.
In general, is not worth obsessing over code.
On the other hand you should code with deliberation and intent. Steven Feurstein Oracle Magazine July /August 2004

A User Agent, like a web browser, uses HTTP to request a HTML document

Documents

Home >Xml > How XSL Works?

Stampa  Stampa


If you've succeeded in running this example, or even if you just want to get on with reading the book, you'll want to know how it works. Let's dissect it:
<?xml version="1.0" encoding="iso-8859-1"?>

This is just the standard XML heading. The interesting point is that an XSLT stylesheet is itself an XML document. I'll have more to say about this later in the chapter. I've used iso-8859-1 character encoding (which is the official name for the character set that Microsoft calls "ANSI") because in Western Europe and North America it's the character set that most text editors support. If you've got a text editor that supports UTF-8 or some other character encoding, feel free to use that instead.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

This is the standard XSLT heading. In XML terms it's an element start tag, and it identifies the document as a stylesheet. The xmlns:xsl attribute is an XML Namespace declaration, which indicates that the prefix xsl is going to be used for elements defined in the W3C XSLT specification: XSLT makes extensive use of XML namespaces, and all the element names defined in the standard are prefixed with this namespace, to avoid any clash with names used in your source document. The version attribute indicates that the stylesheet is only using features from version 1.0 of the XSLT standard, which at the moment is the only version there is.
<xsl:template match="/">
An <xsl:template> element defines a template rule to be triggered when a particular part of the source document is being processed. The attribute match="/" indicates that this particular rule is triggered right at the start of processing the source document. Here «/» is an XPath expression which identifies the root node of the document: an XML document has a hierarchic structure, and in the same way as UNIX uses the special filename «/» to indicate the root of a hierarchic filestore, XPath uses «/» to represent the root of the XML content hierarchy. The DOM model calls this the Document object, but in XPath it is called the root.
<html>
<head>
<title>Today's greeting</title>
</head>
<body>
<p><xsl:value-of select="greeting"/></p>
</body>
</html>
Once this rule is triggered, the body of the template says what output to generate. Most of the template body here is a sequence of HTML elements and text to be copied into the output file. There's one exception: an <xsl:value-of> element, which we recognize as an XSL instruction because it uses the namespace prefix xsl. This particular instruction copies the value of a node in the source document to the output document. . The SELECT attribute of the element specifies the node for which the value should be evaluated. The XPath expression «greeting>> means: "find the set of all <greeting> elements that are children of the node that this template rule is currently processing". In this case, this means the <greeting> element that's the outermost element of the source document. The <xsl:value-of> instruction then extracts the text node of this element, and copies it to the output at the relevant place, in other words within the generated <p> element.

All that remains is to finish what we started:

</xsl:template>
</xsl:stylesheet>
In fact, for a simple stylesheet like the one shown above, you can cut out some of the red tape. Since there is only one template rule, the <xsl:template> element can actually be omitted. The following is a complete, valid stylesheet equivalent to the preceding one:
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<head>
<title>Today's greeting</title>
</head>
<body>
<p><xsl:value-of select="greeting"/></p>
</body>
</html>
This simplified syntax is designed to make XSLT look familiar to people who have learnt to use proprietary template languages which allow you to write a skeleton HTML page with special tags (analogous to <xsl:value-of>) to insert variable data at the appropriate place. But as we'll see, XSLT is much more powerful than that.

Why would you want to place today's greeting in a separate XML file and display it using a stylesheet? One reason is that you might want to show the greeting in different ways depending on the context; for example, it might be shown differently on a different device. In this case you could write a different stylesheet to transform the same source document in a different way. This raises the question of how a stylesheet gets selected at run-time. There is no single answer to this question. As we saw above, Saxon and xt have interfaces interfaces that allow you to nominate both the stylesheet and the source document to use. The same thing can also be achieved with the Microsoft XSLT product, though it requires some scripting on the HTML page: the <?xml-stylesheet?> processing instruction which I used in the example above only works if you want to use the same stylesheet every time.







Warning: include(ads/text468x15.html): failed to open stream: No such file or directory in D:\inetpub\webs\fishscriptcom\documents\view_document.php on line 131

Warning: include(): Failed opening 'ads/text468x15.html' for inclusion (include_path='.;C:\php\pear') in D:\inetpub\webs\fishscriptcom\documents\view_document.php on line 131

Tutorial
Iniziare con Xml Oggetti e metodi per la gestione dei documenti Xml con Javascript e ActiveX   [Xml] 
Script
Parsing file Xml Acquisizione e stampa dei dati di un file Xml  [Xml] 
Lettura dei childNodes di un file xml Lettura da xml dei campi del primo elemento disposti in un array  [Xml] 
Semplice esempio xslt/ xml Utilizzo di xslt  [Xml] 
Le 4 fasi di caricamento e parsing di un documento Xml Attraverso un esempio vengono rpese in esame le fasi di caricamento e di validazione utilizzando l'oggetto ActiveXObjectMsxml2.DOMDocument   [Xml] 
Importazione di file xml Stampa di tutti i campi(childNodes) del primo elemento  [Xml] 
Importazione file xml (variante) Stampa di alcuni campi(childNodes) del primo elemento  [Xml] 
Leggere i dati da file Esempio di lettura dati da formati Xml, Html, Txt  [Xml] 
Stampa nodi figli e valori utilizzo metodo documentElement  [Xml] 
Parsing file xml Stampa di tutti i campi(childNodes) del primo elemento  [Xml] 
Interrogare xml attraverso Xsl formattazione e conteggio dei dati   [Xml] 
Esempio Xsl e Xml File xls che estrae e formatta i dati di un file xml  [Xml] 
Template XHTML 1.0 Modello file XHTML   [Xml] 
XHTML 1.0 Strict template Un'altro template Xhtml pronto all'utilizzo con l'impostazione della pagina con <thead>,<tfoot>,<tbody> come raccomandato dal W3c  [Xml] 
Entitą e caratteri speciali Gestione dei caratteri speciali attraverso xsl  [Xml] 
Strutture condizionali in xsl costrutti choose, when e otherwise  [Xml] 

signal Marco Magnani marcomagnani@fishscript.com



Cerca





Anger is creative, depression is useless.
Dyson, Freeman J.


Anger is creative, depression is useless.
Dyson, Freeman J.



Xml... Definizioni: XPath

Oracle... Definizioni: SCN





fishScript.Com is accessible by Mobile access technology as mobile phones, Palm and Pocket PC .

Nicoleta e Marco Magnani tutorial, examples, courses, esempi, corsi, esercizi, appunti vari Dottoressa Nicoleta Dragu Formatrice Docente Insegnante Mediatrice Culturale Dott. Marco Magnani Universita La Sapienza Roma Master Computer Science Hunter College New York , Data Base Administrator DBA oracle System architect

Last modified: 2017-11-30 amministratore@fishscript.comNico and Marco Magnani Software Production
Home|About this Site © 2003-2008 www.fishScript.com ®