【问题标题】:What is the proper way of handling xml-stylesheet :xmlns:blah with haml?用haml处理xml-stylesheet:xmlns:blah的正确方法是什么?
【发布时间】:2010-12-06 18:13:59
【问题描述】:

我正在尝试用一些 xml 命名空间和 xml 样式表连接一个博客。

我目前这样做的丑陋方式如下:

!!! XML
= partial('xmlstyle')
%channel
......blah.....
= partial('xmlend')

在哪里

_xmlstyle.xml.erb 看起来像:

<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
<?xml-stylesheet type="text/css" media="screen" 
href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:atom="http://www.w3.org/2005/Atom" 
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

_xmlend.xml.erb 看起来像:

</rss>

我现在应该坚持使用 erb 吗? 在haml中必须有一种方法可以做到这一点吗?

【问题讨论】:

    标签: rss haml atom-feed merb


    【解决方案1】:

    Haml 没有 XML 样式表指令的语法,但没有理由不能直接包含它们。至于xmlns:blah 属性,您可以使用字符串作为属性名称,如下所示:

    <?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
    <?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
    %rss{"xmlns:content" => "http://purl.org/rss/1.0/modules/content/",
         "xmlns:wfw" => "http://wellformedweb.org/CommentAPI/",
         "xmlns:dc" => "http://purl.org/dc/elements/1.1/",
         "xmlns:atom" => "http://www.w3.org/2005/Atom",
         "xmlns:sy" => "http://purl.org/rss/1.0/modules/syndication/",
         "xmlns:slash" => "http://purl.org/rss/1.0/modules/slash/",
         "xmlns:feedburner" => "http://rssnamespace.org/feedburner/ext/1.0",
         :version => "2.0"}
      %channel
        blah
    

    您还可以将 HTML 样式的属性与 () 一起使用:

    <?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
    <?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
    %rss(xmlns:content="http://purl.org/rss/1.0/modules/content/"
         xmlns:wfw="http://wellformedweb.org/CommentAPI/"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns:atom="http://www.w3.org/2005/Atom"
         xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
         xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
         xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"
         version="2.0")
      %channel
        blah
    

    【讨论】:

    • 太棒了。 %rss{ "xmlns:atom" =&gt; "http://www.w3.org/2005/Atom" }bit 正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 2014-09-23
    • 2010-10-08
    • 2013-07-24
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多