JSTL - Balise XML <x: transform>

le <x:transform> La balise applique une transformation XSL sur un document XML.

Attribut

le <x:transform> tag a les attributs suivants -

Attribut La description Obligatoire Défaut
doc Document XML source pour la transformation XSLT Non Corps
docSystemId URI du document XML d'origine Non Aucun
xslt Feuille de style XSLT fournissant des instructions de transformation Oui Aucun
xsltSystemId URI du document XSLT d'origine Non Aucun
résultat Objet de résultat pour accepter le résultat de la transformation Non Imprimer sur la page
var Variable définie sur le document XML transformé Non Imprimer sur la page
portée Portée de la variable pour exposer le résultat de la transformation Non Aucun

Exemple

Considérez la feuille de style XSLT suivante style.xsl -

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

<xsl:output method = "html" indent = "yes"/>
   <xsl:template match = "/">
      <html>
         <body>
            <xsl:apply-templates/>
         </body>
      </html>
   </xsl:template>

   <xsl:template match = "books">
      <table border = "1" width = "100%">
         <xsl:for-each select = "book">
            <tr>
               <td>
                  <i><xsl:value-of select = "name"/></i>
               </td>
               
               <td>
                  <xsl:value-of select = "author"/>
               </td>
               
               <td>
                  <xsl:value-of select = "price"/>
               </td>
            </tr>
         </xsl:for-each>
      </table>
   </xsl:template>

</xsl:stylesheet>

Considérons maintenant le fichier JSP suivant -

<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix = "x" uri = "http://java.sun.com/jsp/jstl/xml" %>

<html>
   <head>
      <title>JSTL x:transform Tags</title>
   </head>

   <body>
      <h3>Books Info:</h3>
      <c:set var = "xmltext">
         <books>
            <book>
               <name>Padam History</name>
               <author>ZARA</author>
               <price>100</price>
            </book>
          
            <book>
               <name>Great Mistry</name>
               <author>NUHA</author>
               <price>2000</price>
            </book>
         </books>
      </c:set>

      <c:import url = "http://localhost:8080/style.xsl" var = "xslt"/>
      <x:transform xml = "${xmltext}" xslt = "${xslt}"/>

   </body>
</html>

Vous recevrez le résultat suivant -

Books Info:

Padam History

ZARA

100

Great Mistry

NUHA

2000