Balise <x:transform>

JSP 标准标签库Bibliothèque de balises standard JSP

La balise <x:transform> applique XSL à un document XML.

Format de syntaxe

<x:transform
   var="<string>"
   scope="<string>"
   result="<string>"
   doc="<string>"
   docSystemId="<string>"
   xslt="<string>"
   xsltSystemId="<string>"/>

Attributes

La balise <x:transform> possède les attributs suivants :

Attribut Description Requis Valeur par défaut
doc Document XML source non Body
docSystemId URI du document XML source non Aucune
xslt Feuille de style XSLT Oui Aucune
xsltSystemId URI du document XSLT source non Aucune
result Objet destiné à recevoir le résultat de la transformation non Afficher sur la page
var Variable représentant le document XML à transformer non Afficher sur la page
scope Portée de l'attribut var non Aucune


Démonstration d'exemple

Fichier 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>

Le code du fichier main.jsp est le suivant :

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ 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 标签</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>

La sortie est la suivante :


JSP 标准标签库Bibliothèque de balises standard JSP

Autres extensions