2009-10-14 7 views
1

J'essaie de connecter un blog avec des espaces de noms XML et des feuilles de style XML.Quelle est la bonne façon de gérer xml-stylesheet: xmlns: blah avec haml?

La façon laide que je fais cela ressemble actuellement à ceci:

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

_xmlstyle.xml.erb ressemble:

<?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 ressemble à:

</rss> 

Dois-je rester avec erb pour le moment? Il doit y avoir une façon de faire cela dans le bon droit?

Répondre

2

Haml n'a pas de syntaxe pour les directives de feuille de style XML, mais il n'y a pas de raison que vous ne puissiez pas les inclure directement. En ce qui concerne les attributs xmlns:blah, vous pouvez utiliser des chaînes comme les noms d'attributs, comme ceci:

<?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 

Vous pouvez également utiliser les attributs de style HTML avec ():

<?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 
+0

Impressionnant. Le bit '% rss {" xmlns: atom "=>" http://www.w3.org/2005/Atom "}' était exactement ce que je cherchais. –

Questions connexes