<x:transform> タグ

JSP 标准标签库JSP 標準タグライブラリ

<x:transform>タグはXMLドキュメントにXSLを適用します。

構文形式

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

属性

<x:transform>タグには次の属性があります:

属性 説明 必須かどうか デフォルト値
doc ソースXMLドキュメント 否 Body
docSystemId ソースXMLドキュメントのURI 否 无
xslt XSLT スタイルシート である 无
xsltSystemId ソースXSLTドキュメントのURI 否 无
result 変換結果を受け取るオブジェクト 否 Print to page
var 変換されるXMLドキュメントを表す変数 否 Print to page
scope var属性のスコープ 否 无


サンプルデモ

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>

main.jspファイルのコードは次のとおりです:

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

実行結果は次のとおりです:


JSP 标准标签库JSP 標準タグライブラリ

その他の拡張