欢迎光临
我们一直在努力

HTML Just Passing Through

建站超值云服务器,限时71元/月

xmls 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, youd 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, ill present a quick shortcut that allows you
to include arbitrary mixed-content html in your xsl stylesheets output.

the xsl stylesheets input includes some xml document, constrained by
(that is, validated against) a particular dtd. to define the element
containing the arbitrary htmls 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 youve defined the tags, define a
parameter entity that includes all of the html "pass-through" tags
youve 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 xmls extensibility and structure
control into the world of html, would be a better solution. but thats
a topic for another newsletter.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » HTML Just Passing Through
分享到: 更多 (0)

相关推荐

  • 暂无文章