Core JSTL Mastering the JSPT Standard Tag Library [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Core JSTL Mastering the JSPT Standard Tag Library [Electronic resources] - نسخه متنی

David M. Geary

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید











10.8 Accessing External Entities


XML documents often reference entities, which are typically text that is reused among one or more XML documents. Entities can be internal, meaning they are defined within the XML document that uses them, or external, meaning they are defined elsewhere. The JSTL <x:parse> and <x:transform> actions support external entities with attributes that specify URIs that point to an entity's file.

The Web application shown in Figure 10-7 references an external entity that specifies the owner of the Rolodex, which is defined in rolodex.xml.

Figure 10-7. Accessing External Entities


Listing 10.1 on page 424 that specifies a DTD that references an external entity.

The external entity specified in the preceding DTD is named owner and is defined in the file owner.xml. That file is listed in Listing 10.6 on page 446, except that the preceding stylesheet displays the owner of the Rolodex, which is specified with the owner external entity in the Rolodex XML document.

Listing 10.16 rolodex.xml (Specifying a DTD)


<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE rolodex [
<!ELEMENT rolodex
(owner,contact,firstName,lastName,email,phone)>
<!ELEMENT owner (#PCDATA)>
<!ELEMENT contact (#PCDATA)>
<!ELEMENT firstName (#PCDATA)>
<!ELEMENT lastName (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ATTLIST phone home CDATA #REQUIRED>
<!ATTLIST phone work CDATA #IMPLIED>

<!ENTITY owner SYSTEM "owner.xml">
]>
<rolodex>

<owner>&owner;</owner>
<contact>
<firstName>Anna</firstName>
<lastName>Keeney</lastName>
<email>anna.keeney@worldlink.net</email>
<company>BSC, Inc.</company>
<phone type="work">716-873-9644</phone>
<phone type="home">716-834-8772</phone>
</contact>
<contact>
<firstName>Lynn</firstName>
<lastName>Seckinger</lastName>
<company>Sabreware, Inc.</company>
<email>lynn.seckinger@telecom.net</email>
<phone type="work">716-219-2012</phone>
</contact>
<contact>
<firstName>Ronald</firstName>
<lastName>Dunlap</lastName>
<company>World Traders, Inc.</company>
<email>ron.dunlap@worldlink.net</email>
<phone type="work">915-783-6494</phone>
<phone type="home">915-843-8727</phone>
</contact>
</rolodex>


Listing 10.17 owner.xml


<!-- The name of the Rolodex owner -->
Sabreware, Inc.

Listing 10.18 index.jsp (Accessing External Entities)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Accessing External Entities</title>
</head>
<body>
<%@ taglib uri='http://java.sun.com/jstl/core' prefix='c' %>
<%@ taglib uri='http://java.sun.com/jstl/xml' prefix='x' %>
<%-- Import the XML file and XSLT stylesheet --%>
<c:import var='rolodex_xml' url='rolodex.xml'/>
<c:import var='rolodex_xsl' url='rolodex.xsl'/>
<%-- Parse the XML File --%>
<x:parse var='document' xml='${rolodex_xml}'

systemId='http://localhost/core-jstl/xml/external-entities/ '
/>
<%-- Perform the transformation --%>
<x:transform xml='${document}' xslt='${rolodex_xsl}'/>
</body>
</html>


Listing 10.19 rolodex.xsl (Generating HTML for Root Document)


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- Generate HTML for the document root -->
<xsl:template match="/">
<table border='1'>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Company</th>
<th>Email</th>
<th>Work Phone</th>
<th>Home Phone</th>
<xsl:apply-templates/>
</tr>
</table>
</xsl:template>

<xsl:template match="owner">
<p>
<font size='5'>
Rolodex for

<xsl:value-of select='.'/>
</font>
</p>
</xsl:template>
<!-- Create a table row for each item and apply templates -->
<xsl:template match="contact">
<tr><xsl:apply-templates/></tr>
</xsl:template>
<!-- Create table data for each item and apply templates -->
<xsl:template match="contact/*">
<td><xsl:apply-templates/></td>
</xsl:template>
</xsl:stylesheet>




    / 124