在收集生长早期,凝聚性(cohesiveness)是由服务器端完成的,但要牵涉到大批的人工文件管理工作。荣幸的是,跟着收集的日趋成熟,收集开发工具也日臻完美。比方,在.NET框架下,你可以建立种种Web控件来一致设想。
在设想用户/数据交互功用时,怎样让数据的完全性、用户界面的功用性和商务划定规矩的完美完成。本文将供应一个网站实例,并申明XML 和XSLT怎样使你的网站设想天衣无缝。
以下是援用片断:
<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="Submit"> </form> </body> </html>
以上代码段完成了主要功用,但还需用XML和XSLT来对其加以美化。
在XML中,代码有开首和末端标签,而在HTML中没有。INPUT 和BR标签是个惯例,它们不需末端标签。但是,在末端标签标记“>”前加一个正斜杠,可确保HTML相符XML范例。如果在编写HTML剧本时注重顺从这些范例,你就可以将XML/HTML(aka XHTML)转换为不错的HTML页面。
以下是援用片断:
<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="Submit" transform="bigButton"/> </form> 运转以下代码,完成XSLT转换: <?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>
以上代码没法为你完成建立定名空间、定义XML标签、确认DTD或schema。它使你可以建立可行的HTML剧本,并可转化为完全的新页面,无需忧郁设想要素。
在样式表中,用HTML标签的转换属性驱动转换操纵。我曾斟酌用一个FORM窗体作为定义转换操纵所需的用户控件的单位,由于一切用于用户输入的控件都应在一个FORM中。本例中,输出为一个文本INPUT,文本色彩为蓝色;一个高20像素、宽100像素的按钮,字体为18点加粗。我们可以经由过程修正转换属性来转变文本框中的文本色彩。
有多种要领可将静态内容添加到网页中本例中只采纳最简朴的体式格局,即在样式表中增添header和footer。
如今,要建立一个新窗体用于用户输入时,要做的只是建立一个平常窗体。一旦平常窗体经由过程测试,就可以将这些窗体添加到转换中生成主题的HTML输出。你只需记着输入控件范例,并注重把它添加为转换属性即可。
以上就是XML和XSLT连系使网站设想天衣无缝的内容,更多相关内容请关注ki4网(www.ki4.cn)!