<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://shazwazza.com/rss/xslt"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Shazwazza</title>
    <link>https://shazwazza.com/</link>
    <description>My blog which is pretty much just all about coding</description>
    <generator>Articulate, blogging built on Umbraco</generator>
    <image>
      <url>/media/0libq25y/frog.png?rmode=max&amp;v=1da0e911f4e6890</url>
      <title>Shazwazza</title>
      <link>https://shazwazza.com/</link>
    </image>
    <item>
      <guid isPermaLink="false">1164</guid>
      <link>https://shazwazza.com/post/styling-xml-with-css/</link>
      <category>Web Development</category>
      <title>Styling XML with CSS</title>
      <description>&lt;div class="imported-post"&gt;This post was imported from FARMCode.org which has been discontinued. These posts now exist here as an archive. They may contain broken links and images.&lt;/div&gt;I’m sure you’ve heard of XSLT (DON'T GO AWAY I'M NOT SUPPORTING XSLT!). XSLT is used to transform XML into different XML – for example, rendering XML as HTML.&amp;nbsp; An example:  &lt;h2&gt;The XSLT method&lt;/h2&gt;&lt;pre&gt;&amp;lt;album&amp;gt;
	&amp;lt;title&amp;gt;Funkentelechy Vs. The Placebo Syndrome&amp;lt;/title&amp;gt;
	&amp;lt;artist&amp;gt;Parliament&amp;lt;/artist&amp;gt; 
	&amp;lt;year&amp;gt;1976&amp;lt;/year&amp;gt; 
	&amp;lt;funkativity&amp;gt;10&amp;lt;/funkativity&amp;gt; 
&amp;lt;/album&amp;gt;
&lt;/pre&gt;
&lt;p&gt;can be transformed (using XSLT) to this:&lt;/p&gt;&lt;pre&gt;&amp;lt;div class="album"&amp;gt;
	&amp;lt;h1&amp;gt;Funkentelechy Vs. The Placebo Syndrome&amp;lt;/h1&amp;gt;
	&amp;lt;p class="artist"&amp;gt;Parliament&amp;lt;/p&amp;gt;
	&amp;lt;p class="year"&amp;gt;1976&amp;lt;/p&amp;gt;
	&amp;lt;p class="funkativity"&amp;gt;This album has a funkativity rating of 10/10&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Now the question is, "is &lt;code&gt;h1&lt;/code&gt; a better tagname for the artist of the album than &lt;code&gt;artist&lt;/code&gt;?". I'm pretty sure the answer is no. However, the HTML engine has no idea how to display an &lt;code&gt;artist&lt;/code&gt; tag - it treats every unknown tag like a &lt;code&gt;span&lt;/code&gt; tag.&lt;/p&gt;
&lt;h2&gt;The pure CSS method&lt;/h2&gt;
&lt;p&gt;So display information has to come from somewhere else. Some people may find the idea of markup depending entirely on CSS for display abhorrent. I do not. I maintain that reading the source of the &lt;code&gt;album&lt;/code&gt; XML block makes just as much sense as reading the rendered HTML version. And screenreaders...if I was a screenreader I'd want concise and descriptive XML, rather than having to wade through a bunch of HTML crap. And let's be real: everyone's web client supports CSS.&lt;/p&gt;
&lt;p&gt;Styling XML with CSS is actually very simple and very robust. The first thing to understand is that HTML is just a custom &lt;a href="http://www.w3.org/TR/REC-xml-names/#scoping-defaulting" target="_blank"&gt;namespace&lt;/a&gt; of XML. The second thing to understand is you can have multiple namespaces present in any XML document. That means you can use both HTML and, say, a custom namespace...which you can define and set styling rules.&lt;/p&gt;
&lt;p&gt;I won't blather much more. I'll just fill you in on how &lt;a href="http://www.w3.org/TR/css3-namespace/#declaration" target="_blank"&gt;CSS targets namespaces&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;The CSS @namespace declaration&lt;/h3&gt;
&lt;p&gt;In short, I can write up a stylesheet which targets a specific namespace and only a specific namespace. My XML file would look like this:&lt;/p&gt;&lt;pre&gt;&amp;lt;?xml version="1.0" encoding="UTF-8" ?&amp;gt;
&amp;lt;albums xmlns="http://jdiacono.org/music"&amp;gt;
	&amp;lt;album&amp;gt;
		&amp;lt;title&amp;gt;Funkentelechy Vs. The Placebo Syndrome&amp;lt;/title&amp;gt;
		&amp;lt;artist&amp;gt;Parliament&amp;lt;/artist&amp;gt; 
		&amp;lt;year&amp;gt;1976&amp;lt;/year&amp;gt; 
		&amp;lt;funkativity&amp;gt;10&amp;lt;/funkativity&amp;gt; 
	&amp;lt;/album&amp;gt;
&amp;lt;albums&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Here I declare that the XML inside and including the &lt;code&gt;albums&lt;/code&gt; block is of the namespace &lt;code&gt;http://jdiacono.org/music&lt;/code&gt;. Don't be misled by the namespace looking like a URL...I haven't even registered &lt;strong&gt;jdiacono.org&lt;/strong&gt; and this is still valid. This is because namespaces are actually just unique, case-sensitive strings, and URLs tend to be unique and full of information. Let it be known that this block is &lt;em&gt;all there is&lt;/em&gt;. It is a completely self descriptive block of pure data, which references nothing external.&lt;/p&gt;
&lt;p&gt;Now to style this...here is my CSS:&lt;/p&gt;&lt;pre&gt;@namespace url("http://jdiacono.org/music");

albums {
	display:block;
	}
	
album {
	display:list-item;
	list-style-type:decimal;
	margin-bottom:0.5em;
	padding:0.5em;
	border:1px solid;
	}
	
album title {
	display:block;
	font-size:2em;
	font-weight:bold;
	border-bottom:1px dashed;
	}
	
album artist {
	display:block;
	font-size:0.9em;
	}
	
album year {
	display:block;
	font-weight:bold;
	letter-spacing:0.4em;
	color:Green;
	}
	
album funkativity {
	display:block;
	font-style:italic;
	}
	
album funkativity:before {
	content: "This album has a funkativity rating of ";
	}
	
album funkativity:after {
	content: "/10";
	}
&lt;/pre&gt;
&lt;p&gt;Now I have another example that is much more nourishing, which uses HTML and a custom XML namespace in the same page. You will need a browser other than IE to view this.&lt;/p&gt;
&lt;p&gt;&lt;a href="/sourcecode/sourcecode/cssNamespaces/cssNamespaces.xml" target="_blank"&gt;farmcode.org/sourcecode/sourcecode/cssNamespaces/cssNamespaces.xml&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;UPDATE: &lt;a href="http://ie.microsoft.com/testdrive/"&gt;Looks like IE9 is supporting this!&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:14 Z</pubDate>
      <a10:updated>2023-03-23T15:08:14Z</a10:updated>
    </item>
  </channel>
</rss>