淺談XML和XSLT結(jié)合使網(wǎng)站設(shè)計(jì)渾然一體_Xml教程
推薦:在XPath查詢中指定軸以下示例顯示如何在 XPath 查詢中指定軸。這些示例中的 XPath 查詢都在 SampleSchema1.xml 中所包含的映射架構(gòu)上指定。有關(guān)此示例架構(gòu)的信息,請(qǐng)參見(jiàn)示例 XPath 查詢。 示例 A. 檢索上下文
XML和XSLT的轉(zhuǎn)換使Web設(shè)計(jì)受益無(wú)窮。借助XML和 XSLT轉(zhuǎn)換,你可以實(shí)現(xiàn)將動(dòng)態(tài)用語(yǔ)(dynamic verbiage)和網(wǎng)站內(nèi)容存儲(chǔ)在數(shù)據(jù)庫(kù)中。你可以在XML中傳輸數(shù)據(jù)庫(kù),然后再通過(guò)XSLT轉(zhuǎn)換將其轉(zhuǎn)變?yōu)镠TML腳本。
在網(wǎng)絡(luò)發(fā)展初期,凝聚性(cohesiveness)是由服務(wù)器端實(shí)現(xiàn)的,但要牽涉到大量的人工文件管理工作。幸運(yùn)的是,隨著網(wǎng)絡(luò)的日益成熟,網(wǎng)絡(luò)開(kāi)發(fā)工具也日臻完善。例如,在.NET框架下,你可以創(chuàng)建各種Web控件來(lái)統(tǒng)一設(shè)計(jì)。
在設(shè)計(jì)用戶/數(shù)據(jù)交互功能時(shí),如何讓數(shù)據(jù)的完整性、用戶界面的功能性和商務(wù)規(guī)則的完善實(shí)現(xiàn)。本文將提供一個(gè)網(wǎng)站實(shí)例,并說(shuō)明XML 和XSLT如何使你的網(wǎng)站設(shè)計(jì)渾然一體。
以下是引用片段:
<html>
<head>
</head>
<body>
<form method="POST" name="thisForm" id="thisForm" action="somepage.php">
<input type="text" name="txtText" id="txtText" size="25"><br>
<input type="submit" name="btnSubmit" id="btnSubmit" value="http://www.hl5o.cn/Submit">
</form>
</body>
</html>
以上代碼段完成了主要功能,但還需用XML和XSLT來(lái)對(duì)其加以美化。
在XML中,代碼有開(kāi)頭和結(jié)尾標(biāo)簽,而在HTML中沒(méi)有。INPUT 和BR標(biāo)簽是個(gè)特例,它們不需結(jié)尾標(biāo)簽。然而,在結(jié)尾標(biāo)簽標(biāo)記“>”前加一個(gè)正斜杠,可確保HTML符合XML規(guī)范。如果在編寫HTML腳本時(shí)注意遵從這些規(guī)范,你就能夠?qū)ML/HTML(aka XHTML)轉(zhuǎn)換為不錯(cuò)的HTML頁(yè)面。
以下是引用片段:
<form method="POST" name="thisForm" id="thisForm" action="somepage.php">
<input type="text" name="txtText" id="txtText" size="25" transform="blueText"/>
<br/>
<input type="submit" name="btnSubmit" id="btnSubmit" value="http://www.hl5o.cn/Submit"
transform="bigButton"/>
</form> 運(yùn)行下列代碼,完成XSLT轉(zhuǎn)換:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
>
<xsl:output method="html"/>
<xsl:template match="/">
<table width="100%" cellpadding="0" cellspacing="0">
<tr><td align="center">This is the defined header</td></tr>
<tr><td><xsl:apply-templates select="//form"/></td></tr>
<tr><td align="center">This is the defined footer</td></tr>
</table>
</xsl:template>
<xsl:template match="form">
<xsl:element name="form">
<xsl:attribute name="method"><xsl:value-of
select="@method"/></xsl:attribute>
<xsl:attribute name="action"><xsl:value-of
select="@action"/></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:apply-templates select="*"/>
</xsl:element>
</xsl:template><xsl:template match="*">
<xsl:choose>
<xsl:when test="@transform='blueText'"><xsl:element name="input">
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="type">text</xsl:attribute>
<xsl:attribute name="style">color:blue</xsl:attribute>
<xsl:if test="@value"><xsl:attribute name="value"><xsl:value-of
select="@value"/></xsl:attribute></xsl:if>
</xsl:element>
</xsl:when>
<xsl:when test="@transform='redText'"><xsl:element name="input">
<xsl:attribute name="name"><xsl:value-of
select="@name"/></xsl:attribute>
<xsl:attribute name="id"><xsl:value-of
select="@id"/></xsl:attribute>
<xsl:attribute name="type">text</xsl:attribute>
<xsl:attribute name="style">color:red</xsl:attribute>
<xsl:if test="@value"><xsl:attribute name="value"><xsl:value-of
select="@value"/></xsl:attribute></xsl:if>
</xsl:element>
</xsl:when>
<xsl:when test="@transform='bigButton'"><xsl:element name="input">
<xsl:attribute name="name"><xsl:value-of
select="@name"/></xsl:attribute>
<xsl:attribute name="id"><xsl:value-of
select="@id"/></xsl:attribute>
<xsl:attribute name="style">height:30px;width:100px;font-
size:18pt;font-weight:700;</xsl:attribute>
<xsl:attribute name="value"><xsl:value-of
select="@value"/></xsl:attribute>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
以上代碼無(wú)法為你實(shí)現(xiàn)創(chuàng)建命名空間、定義XML標(biāo)簽、確認(rèn)DTD或schema。它使你能夠創(chuàng)建可行的HTML腳本,并可轉(zhuǎn)化為完整的新頁(yè)面,無(wú)需擔(dān)心設(shè)計(jì)因素。
在樣式表中,用HTML標(biāo)簽的轉(zhuǎn)換屬性驅(qū)動(dòng)轉(zhuǎn)換操作。我曾考慮用一個(gè)FORM窗體作為定義轉(zhuǎn)換操作所需的用戶控件的單元,因?yàn)樗杏糜谟脩糨斎氲目丶紤?yīng)在一個(gè)FORM中。本例中,輸出為一個(gè)文本INPUT,文本顏色為藍(lán)色;一個(gè)高20像素、寬100像素的按鈕,字體為18點(diǎn)加粗。我們可以通過(guò)修改轉(zhuǎn)換屬性來(lái)改變文本框中的文本顏色。
有多種方法可將靜態(tài)內(nèi)容添加到網(wǎng)頁(yè)中本例中只采用最簡(jiǎn)單的方式,即在樣式表中增加header和footer。
現(xiàn)在,要?jiǎng)?chuàng)建一個(gè)新窗體用于用戶輸入時(shí),要做的只是創(chuàng)建一個(gè)一般窗體。一旦一般窗體通過(guò)測(cè)試,就可以將這些窗體添加到轉(zhuǎn)換中生成主題的HTML輸出。你只要記住輸入控件類型,并注意把它添加為轉(zhuǎn)換屬性即可。
分享:XML讀取數(shù)據(jù)到內(nèi)存從XML中讀取數(shù)據(jù)到內(nèi)存的實(shí)例: public clsSimuResultByOneGoods GetOneGoodsSimulationXML(string PathAndFileName) {
- xml創(chuàng)建節(jié)點(diǎn)(根節(jié)點(diǎn)、子節(jié)點(diǎn))
- WML開(kāi)發(fā)教程之 WAP網(wǎng)站服務(wù)器配置方法
- WMLScript的語(yǔ)法基礎(chǔ)
- 收集的WML Script標(biāo)準(zhǔn)函數(shù)庫(kù)
- WML教程之文本框控件Input
- 無(wú)線標(biāo)記語(yǔ)言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)
- xml文件的結(jié)構(gòu)解讀
- 關(guān)于XSL - XSL教程
- 選擇模式 - XSL教程 - 2
- XPath入門 - XSL教程 - 3
- 匹配模式 - XSL教程 - 4
- 測(cè)試模式 - XSL教程 - 5
- 相關(guān)鏈接:
- 教程說(shuō)明:
Xml教程-淺談XML和XSLT結(jié)合使網(wǎng)站設(shè)計(jì)渾然一體
。