Jump to content

XML website structure


vchris

Recommended Posts

I was wondering what is the structure when creating a website template in xml? Should it be something like this:

<header><banner>Website Title</banner></header><leftnav><navlist1><link>list item 1</link><link>list item 2</link>...</navlist1></leftnav><content><heading>Header 1</heading><text>blah blah</text></content><footer><lastmod>03/10/2006</lastmod></footer>

Of course I left the Xlinks out of this since I'm not that advanced yet.

Link to comment
Share on other sites

Well, um... how should I put it.... it can be anything you want. That's just the beauty of XML. There's no right way. You define it all.If you want opinions about what you have defined as right, then... hm... I would prefer calling "leftnav" simply "nav" or "navigation" or maybe even "menu". After all, appearance is not defined by XML and you might want to move the nav to the top some day.Other than that, I think it all feels readable.Note however that you don't need XLink. XLink should only be used if this XML is not going to be transformed to XHTML or another language with it's own linking system. For example, in XHTML you use the <a> element to define a link and use the href attribute and all.... bla bla. In SVG, the <a> element is present, but the specification doesn't provide the href attribute or any other sort of system for linking. That's where XLink kicks in.

Link to comment
Share on other sites

Thanks for your suggestion boen_robot! :)Wouldn't xlink be used for linking the items in the navigation? I'm starting my very first layout in xml, xslt and css. Updates to come.

Link to comment
Share on other sites

Wouldn't xlink be used for linking the items in the navigation?
As I said: if you won't be transforming the XML to XHTML, then yes. But apparently, you will, so no. Creating the links that another language (XHTML in this case) is using is part of XSLT's duties. You do need to store the URL somewhere though. I would suggest something like:
<link to="URL">list item 1</link>

Link to comment
Share on other sites

Here's what I got:

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/layout"><html>  <head>	<title><xsl:value-of select="header/banner"/></title>	  <style type="text/css">	ul li { display: inline; }	</style>  </head>  <body>	<h1><xsl:value-of select="header/banner"/></h1>	<ul>		<xsl:for-each select="navigation">			<li><xsl:value-of select="item"/></li>		</xsl:for-each>	</ul>	<xsl:for-each select="content">		<h2><xsl:value-of select="heading"/></h2>		<p><xsl:value-of select="text"/></p>	</xsl:for-each>	<p><xsl:value-of select="footer/lastmod"/></p>  </body></html></xsl:template></xsl:stylesheet>

It display correctly but the only problem is the for-each. The output for the nav is only the first list item. I then tried using <xsl:for-each select="navigation/item"> and <xsl:value-of select="."/> and this worked perfectly. But why isn't the way I have above looping?

Link to comment
Share on other sites

Because you only have one "navigation" element to store all "item" elements. So scince you have one element- you incoke the for-each once. You have for example 5 elements, you invoke the for-each 5 times.

Link to comment
Share on other sites

So the solution would be:<xsl:for-each select="navigation/item"><li><xsl:value-of select="."/></li></xsl:for-each>or is there a better way to do this?

Link to comment
Share on other sites

Well, I would personally do it like:

<xsl:for-each select="navigation">	<ul>		<xsl:for-each select="item">			<li><xsl:value-of select="."/></li>		</xsl:for-each>	</ul></xsl:for-each>

That way, if you don't have a navigaiton in the XML that uses the stylesheet, you won't get the extra <ul> and if you have more then one, you'll have a new <ul> to hold every menu.

Link to comment
Share on other sites

Thanks! it's fixed now. Only issue I got is including a stylesheet in my xml file. I have this line <?xml-stylesheet type="text/css" href="layout.css"?> after including the xsl file. Here is my css file:

banner { color: blue; }item { display: inline; }lastmod { font-size: 10px; }

The css doesn't seem to apply at all... path is correct.

Link to comment
Share on other sites

That is because the XSLT overriddes the CSS. CSS on XML is only used for browsers that don't support XSLT.If you want to style an XML that is using XSLT, you must style the output instead. Looking at your example above, you've done that already actually. I'm talking about the lines:

	  <style type="text/css">	ul li { display: inline; }	</style>

Using an external CSS file would requre the same (XHTML) selectors and must be called in the XSLT the XHTML way (<link/> or @import).

Link to comment
Share on other sites

I am now trying to create links in my navigation. I checked out the xlink tutorial on this site but it only showed the xml version not xslt. I have this in xml:

<navigation><item url="http://www.google.ca">item 1</item></navigation>

How would I get the url with xslt?

Link to comment
Share on other sites

I am now trying to create links in my navigation. I checked out the xlink tutorial on this site but it only showed the xml version not xslt. I have this in xml:
<navigation><item url="http://www.google.ca">item 1</item></navigation>

How would I get the url with xslt?

Stop reffering to XLink will you? :) Giving your initial code as a base, it should look something like:
<xsl:for-each select="navigation">	<ul>		<xsl:for-each select="item">			<li><a href="{@url}"><xsl:value-of select="."/></a></li>		</xsl:for-each>	</ul></xsl:for-each>

This particular technique (the parenthesis with an XPath expression in them) is called attribute value template or AVT. It's one of the most significant things the XSLT tutorial is missing unfortunatly.

Link to comment
Share on other sites

Stop reffering to XLink will you? :) Giving your initial code as a base, it should look something like:
<xsl:for-each select="navigation">	<ul>		<xsl:for-each select="item">			<li><a href="{@url}"><xsl:value-of select="."/></a></li>		</xsl:for-each>	</ul></xsl:for-each>

This particular technique (the parenthesis with an XPath expression in them) is called attribute value template or AVT. It's one of the most significant things the XSLT tutorial is missing unfortunatly.

What about Xlink? jk :) :)So basically the {} replace <xsl:value-of select="@url"/>?
Link to comment
Share on other sites

So basically the {} replace <xsl:value-of select="@url"/>?
Exactly. And it's only used on attributes' values that are part of the output. There are few exclusions on this rule, like the name attribute in the xsl:element and xsl:attribute elements. Their values can also contain AVT.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...