Perl Cd Bookshelf [Electronic resources] نسخه متنی

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

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

Perl Cd Bookshelf [Electronic resources] - نسخه متنی

Mark V. Scardina, Ben ChangandJinyu Wang

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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






Creating the XSL Stylesheets


It is now time to turn to the stylesheet that will be used to produce HTML or WML pages based upon the specific device. We will examine the stylesheet for DVDs; however, the book and CD stylesheets are the same except for the names of a few elements. Because this is a complex stylesheet, we will discuss each template.

The following section is where the parameter values are passed into the stylesheet. In this case, we use the optional select="value" attribute to set a default value if a parameter is missing. This is also an effective way to debug a stylesheet that uses a variety of parameter values.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform">
<xsl:param name="Graphics" select="'ON'"/>
<xsl:param name="ColorDepth" select="'16'"/>
<xsl:param name="Profile" select="'PC'"/>

The following xsl:choose section handles the setting of the character set and the output file type since this cannot be done within a template in XSLT 1.0. It chooses between inserting the HTML and WML DOCTYPE declarations as well as the specific output encoding, which in this case is UTF-8, based upon the active Profile.

<xsl:choose>
<xsl:when select="$Profile='PC'">
<xsl:output encoding="UTF-8" method="HTML"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$Profile='PHONE'">
<xsl:output encoding="UTF-8" method="XML"
doctype-public="-//WAPFORUM//DTD WML 1.1//EN"
doctype-system="http://www.wapforum.org/DTD/wml_1.1.xml"/>
</xsl:when>
<xsl:otherwise>
<xsl:output encoding="UTF-8" method="HTML"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>

The following mode template allows you to control execution based upon the Profile passed in and sets the basis for executing the following mode-specific templates:

<xsl:template match="/">
<xsl:if test="$Profile='PC'">
<xsl:apply-templates mode="PC" select="/" />
</xsl:if>
<xsl:if test="$Profile='PDA'">
<xsl:apply-templates mode="PC" select="/" />
</xsl:if>
<xsl:if test="$Profile='PHONE'">
<xsl:apply-templates mode="PHONE" select="/" />
</xsl:if>
</xsl:template>

The following is the template that is executed if the mode is PC or PDA and uses the corresponding mode parameters to configure the display for Graphics and ColorDepth. Note that the images are differentiated by different paths in the HREF attribute, which is created from the URL attribute in the input XML document.

<xsl:template match="DVDcatalog" mode="PC | PDA">
<html>
<body>
<table>
<tr>
<th>ISBN</th>
<td>Title</td>
<td>Director</td>
<td>Studio</td>
<td>Year</td>
<xsl:if test="$Graphics='ON'">
<td>Picture</td>
</xsl:if>
<td>Price</td>
</tr>
<xsl:for-each select="dvd">
<tr>
<td><xsl:value-of select="ISBN"/></td>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="director_lastname"/></td>
<td><xsl:value-of select="studio"/></td>
<td><xsl:value-of select="year"/></td>
<xsl:if test="$Graphics='ON'">
<td>
<xsl:if test="$ColorDepth = 16">
<img href="/>
</xsl:if>
<xsl:if test="$ColorDepth = 64">
<img href="/>
</xsl:if>
</td>
</xsl:if>
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

This final template produces the WML output for the PHONE mode. Since for our example this mode does not support graphics, you don’t have to handle them within the template. Figure 19-1 shows an example of the output on a phone.

<xsl:template match="DVDcatalog" mode="PHONE">
<wml>
<card>
<xsl:for-each select="dvd">
<p>
ISBN: <xsl:value-of select="ISBN"/><br/>
Title: <xsl:value-of select="title"/><br/>
Director: <xsl:value-of select="director_lastname"/><br/>
Studio: <xsl:value-of select="studio"/><br/>
Year: <xsl:value-of select="year"/><br/>
Price: <xsl:value-of select="price"/><br/>
</p>
</xsl:for-each>
</card>
</wml>
</xsl:template>
</xsl:stylesheet>


Figure 19-1: DVD listing on WML phone

/ 218