1 / 25

X S L T

X S L T. Julio Pacheco. Prerequisitos. HTML / XHTML XML / XML Namespaces XPath. XSL. XSL describe como se desplegara un documento XML. Para que sirve XSLT ?. Documentos XSLT ( E x tensible S tylesheet T ransformations) es tecnología para procesar documentos XML

kineks
Télécharger la présentation

X S L T

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. X S L T Julio Pacheco

  2. Prerequisitos • HTML / XHTML • XML / XML Namespaces • XPath

  3. XSL • XSL describe como se desplegara un documento XML

  4. Para que sirve XSLT ? • Documentos XSLT (Extensible Stylesheet Transformations) es tecnología para procesar documentos XML • Herramienta de traducción XML -> HTML, PDF, DOC, XLS… • XSLT = conversión de datos entre aplicaciones • XSLT usa XPath para navegar

  5. Para que sirve XSLT ? Es un lenguaje para transformar la estructurade un documento XML

  6. Como funciona XSLT ?

  7. Como funciona XSLT

  8. XSLT – Documento XML <?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xsl" href="hola.xsl"?> <saludo>Hola, mundo!</saludo>

  9. XSLT – Hoja de Estilo <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head><title>Un Saludo</title></head> <body> <p><font color="red“ face=“arial”><strong> <xsl:value-of select="saludo"/> </strong></font></p> </body> </html> </xsl:template> </xsl:stylesheet>

  10. Procesadores XSLT • Aplicación de una hoja de estilo a una fuente XML para producir una salida • MSXML3 SP4 (Internet Explorer)http://www.microsoft.com/xml • Saxonhttp://users.iclway.co.uk/mhkay/saxon/ • Xalanhttp://xml.apache.org/xalan/overview.html

  11. Navegadores XSLT • La mayoría de navegadores actuales ya incorporan el procesador de XSLT: • Mozilla Firefox • Internet Explorer versiones superiores a 5.0 • Netscape • Opera • Etc..

  12. Detalles XSLT • XSLT es un lenguaje de programación. • Lenguaje de transformación basado en hojas de estilo. • XSL:FO, transformaciones que no sean XML. • Estilo de programación: • AWK • ML • Scheme • Nada que ver con C, C++, Java, etc.

  13. Instrucciones XSLT Formato y elementos de un documento XSL: • Formado por instrucciones XSLT y tags HTML. • Instrucción <xsl:template> • Se utiliza para relacionar el template con el documento XML. <xsl:template match="/"> • Instrucción <xsl:value-of> • Extraemos un valor del documento XML. <xsl:value-of select="catalog/cd/title"/>

  14. Instrucciones XSLT • Instrucción <xsl:for-each> • Se utiliza para seleccionar todos los elementos de un nodo concreto del documento XML. <xsl:for-each select="catalog/cd"> nodo </xsl:for-each> • Instrucción <xsl:sort> • Ordenar los elementos dentro de un <xsl:for-each>. <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> nodo </xsl:for-each>

  15. Instrucciones XSLT • Instrucción <xsl:if> • Se utiliza para condicionar . <xsl:for-each select="catalog/cd"> <xsl:if test="price &gt; 10"> nodo </xsl:if> </xsl:for-each>

  16. Instrucciones XSLT • Instrucción <xsl:choose> • Se utiliza para realizar múltiples preguntas condicionales. • Se debe utilizar junto a <xsl:when> y <xsl:otherwise>. <xsl:choose> <xsl:when test="expression"> ... some output ... </xsl:when> <xsl:otherwise> ... some output .... </xsl:otherwise> </xsl:choose>

  17. Instrucciones XSLT • Instrucción <xsl:apply-templates> • Aplica el template indicado a un tipo de nodo concreto. • Declaración del template: <xsl:template match="artist"> Artist: <span style="color:#00ff00"> <xsl:value-of select="."/></span> <br /> </xsl:template>

  18. Instrucciones XSLT • Instrucción <xsl:apply-templates> • Aplicación del template: <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <xsl:apply-templates/> </body> </html> </xsl:template>

  19. Instrucciones XSLT • Algunas funciones XSLT: • Funciones especiales: • Funciones con nodos:

  20. Instrucciones XSLT • Algunas funciones XSLT: • Funciones con carácteres:

  21. Ejemplo 2 • cdcatalog.xml

  22. Ejemplo 2 • cdcatalog.xsl

  23. Ejemplo 2 • Mostramos cdcatalog.xml por pantalla...

  24. Ejemplo Divisas

  25. Referencias www.w3schools.com

More Related