English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

<x:transform>タグ

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                変換結果を受け取るオブジェクト                いいえ                ページに印刷
                var                変換されたXMLドキュメントを表す変数                いいえ                ページに印刷
                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>
<h2>Books Info:</h2>
<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 スタンダードタグライブラリ