您好,欢迎访问一九零五行业门户网

XML和XSLT结合使网站设计浑然一体

xml和xslt的转换使web设计受益无穷。借助xml和 xslt转换,你可以实现将动态用语(dynamic verbiage)和网站内容存储在数据库中。你可以在xml中传输数据库,然后再通过xslt转换将其转变为html脚本。
在网络发展初期,凝聚性(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结合使网站设计浑然一体的内容。
其它类似信息

推荐信息