Latest web development tutorials

<X: trasformare> tag

Biblioteca JSP Standard Tag Biblioteca JSP Standard Tag

<X: trasformare> tag per applicare un XSL nei documenti XML.

sintassi

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

proprietà

<X: trasformare> tag ha i seguenti attributi:

proprietà descrizione Se necessario difetto
doc documento XML di origine no corpo
docSystemId URI documento XML di origine no no
XSLT foglio di stile XSLT è no
xsltSystemId URI documento di origine XSLT no no
risultato Ricevere l'oggetto risultati di conversione no Stampa la pagina
var A nome della variabile di documento XML convertito no Stampa la pagina
portata attributo var Scope no no


Esempi Demo

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

codice del file main.jsp è il seguente:

<%@ 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>

I risultati sono i seguenti:


Biblioteca JSP Standard Tag Biblioteca JSP Standard Tag