JSTL - XML <x:out> 標籤



<x:out> 標籤顯示 XPath 表示式的結果。它的功能與 <%= %> JSP 語法相同。

屬性

<x:out> 標籤具有以下屬性:

屬性 描述 必填 預設值
select 要評估為字串的 XPath 表示式,通常使用 XPath 變數
escapeXml 如果標籤應該轉義特殊的 XML 字元,則為真 true

示例

讓我們舉一個例子,它將涵蓋標籤 (a) <x:out>,(b) <x:parse>

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

      <x:parse xml = "${xmltext}" var = "output"/>
      <b>The title of the first book is</b>: 
      <x:out select = "$output/books/book[1]/name" />
      <br>
      
      <b>The price of the second book</b>: 
      <x:out select = "$output/books/book[2]/price" />
   
   </body>
</html>

以上程式碼將產生以下結果:

Books Info:

The title of the first book is: Padam History The price of the second book: 2000
jsp_standard_tag_library.htm
廣告

© . All rights reserved.