• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

HTML Just Passing Through

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 12次 | 进入软件测试论坛讨论

领测软件测试网 XML‘’s many applications include one traditionally handled by HTML,
document source. Sometimes you want to include some HTML in your XML
source; particularly when styling your XML with XSL to HTML, you may
want some literal HTML in the output. In some cases, you‘’d just like to
include some well-formed mixed-content HTML in your XML, and not worry
too much about controlling its structure.

Writing explicit XSL rules for each HTML tag would be tedious and hard
to maintain. This week, I‘’ll present a quick shortcut that allows you
to include arbitrary mixed-content HTML in your XSL stylesheet‘’s output.

The XSL stylesheet‘’s input includes some XML document, constrained by
(that is, validated against) a particular DTD. To define the element
containing the arbitrary HTML‘’s content model, simply define content
models for each of the HTML elements you want to use and their
attribute lists. For example, define the <a?tag for hyperlinks like
this:

?!ELEMENT a (#PCDATA)*?BR>
?!ATTLIST a
href CDATA #IMPLIED
target CDATA #IMPLIED
name CDATA #IMPLIED?BR>
(This example is simplified, since it allows only unformatted text
inside the hyperlink text node.) Create a definition like this for each
HTML tag you wish to use. After you‘’ve defined the tags, define a
parameter entity that includes all of the HTML "pass-through" tags
you‘’ve defined:

?!ENTITY % htmlpassthru
"a|i|b|code|br|tr|td|th|img|font|em"?BR>
Anywhere in the DTD you want to include mixed-content HTML, use this
parameter entity in the DTD. For example:

?!ELEMENT HtmlHelpText (#PCDATA|%htmlpassthru;)*?BR>

Now for the stylesheet. Defining a separate rule for each possible
HTML element within a HtmlHelpText element would be extremely tedious.
Fortunately, a single rule can handle all such elements. Define an XSL
rule that matches the tag name AND uses <xsl:copy-of?to copy the
entire node (including attributes) to the output.

?!-- EXAMPLE XSL stylesheet --?BR>
?xsl:template
match="a|i|b|code|br|tr|td|th|img|font|em"?BR> ?xsl:copy-of select="."/?BR> ?/xsl:template?BR>
?!-- End EXAMPLE --?BR>
Any nodes in the XML input tree with these tags will be copied to the
output structure unmodified, attributes and all.

This technique is somewhat "quick-and-dirty". Choosing XHTML, which
reformulates HTML as XML and brings XML‘’s extensibility and structure
control into the world of HTML, would be a better solution. But that‘’s
a topic for another newsletter.

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网