<X: forEach> tag
Suivant: <x: choisissez>, < x: quand>, <x: autrement> tag
<X: forEach> est utilisée pour boucler à travers les noeuds d'un document XML.
syntaxe
<x:forEach var="<string>" select="<string>" begin="<int>" end="<int>" step="<int>" varStatus="<string>">
propriété
<X: forEach> balise a les attributs suivants:
propriété | description | le cas échéant | Par défaut |
---|---|---|---|
sélectionner | expression XPath à calculer | il est | aucun |
var | Variable est utilisé pour stocker le projet en cours | aucun | aucun |
commencer | Index de départ iterator | aucun | aucun |
fin | Indice de fin iterator | aucun | aucun |
étape | étape de Iteration | aucun | aucun |
varStatus | Statut des variables stockées au nom de iterator | aucun | aucun |
Exemples Démo
<%@ 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:forEach 标签</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"/> <ul class="list"> <x:forEach select="$output/books/book/name" var="item"> <li>Book Name: <x:out select="$item" /></li> </x:forEach> </ul> </body> </html>
Les résultats sont les suivants:
BOOKS INFO: Book Name: Padam History Book Name: Great Mistry
Suivant: <x: choisissez>, < x: quand>, <x: autrement> tag