Advanced JSP Sample : XML/XSL Integration

Previous Contents Next

OTN provides two versions of this sample: one using the SQL and XML utility Tags, and one using the Oracle XML-SQL utility and XML Utility tag.

Using the SQL and XML utility Tags

Contents

Purpose

Integrate extensible markup language (XML) and extensible stylesheet language (XSL) with JSPs using the XML and SQL Utility tags provided with OC4J JSP.

Remarks

XML and XSL support a clean separation of application data from the rules or logic that transform that data into a particular presentation format. XML is the standard used to represent data; XSL is the standard used to represent transformation rules.

This example uses the dbQueryTag in the SQL Tag library to generate XML output for SQL queries on Countries and Cities. Then it uses the xml:transform tag to transform the generated XML into HTML with the use of a stylesheet. These SQL and XML tags are provided as part of the XML and XSL Tag Support in OC4J JSP.

 

Code from XslCities.jsp

<%-- Define the tag libraries --%>
<%@ taglib uri="/WEB-INF/xml.tld" prefix="xml" %>
<%@ taglib uri="/WEB-INF/sqltaglib.tld" prefix="sql" %>
... <%--
Execute the query to fetch the Cities details in XML
format using the dbQuery tag. Then transform the XML
into HTML using the xml:transform tag
--%>
<sql:dbOpen dataSource="jdbc/OTN9iDS" >
<%-- use the XSL file to transform the XML output --%>
<xml:transform href="XmlCities.xsl" >
<sql:dbQuery output="xml" >
SELECT id AS "Id",name AS "Name",
NVL(state_province,'Data Not Available') AS "StateProvince",
time_zone_to_gmt AS "TimeZone"
FROM cities
WHERE con_id = <%=l_param%>
ORDER BY name
</sql:dbQuery>
</xml:transform>
</sql:dbOpen>
...

 

Source Code Listings

Using the Oracle XML-SQL utility and XML Utility tag

Contents

Purpose

Generate eXtensible Markup Language (XML) using the Oracle XML-SQL Utility and transform the XML to HTML using XML Utility tag.

Remarks

XML and XSL support a clean separation of application data from the rules or logic that transform that data into a particular presentation format. XML is the standard used to represent data; XSL is the standard used to represent transformation rules.

Here, a JSP generates XML and applies an XSL stylesheet to produce HTML for presentation. This example uses the Oracle XML-SQL Utility. This very useful package, can convert a JDBC result set into formatted XML output, and can insert XML data into a canonical definition of SQL tables.

This example also uses the xml:transform tag provided as part of the XML and XSL Tag Support in OC4J JSP to apply an XSL stylesheet to the final XML, producing HTML in the desired format.

Code from XslCities.jsp

<% // Variable to store xml output %>
<% String l_xmldoc="";
String l_param = request.getParameter("CountryId");
if (l_param != null) {
%>
<jml:setProperty name="xmlBean" property="CountryId"
value="<%=l_param%>" />
<% l_xmldoc = xmlBean.getCities(); %>
<% // use the XSL file to transform the XML output %>
<jml:transform href="XmlCities.xsl" >
<%=l_xmldoc %>

</jml:transform>

 

Source Code Listings


Previous Contents Next
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy