PDA

View Full Version : Attaching a style sheet to an xml sitemap



chandrika
05-12-2008, 07:22 AM
Is it possible with an xml sitemap, to attach a style sheet to it, so that when the sitemap is viewed in a browser, the links will be clickable.

i get alot of traffic to my sitemap, so wanted to make it easy to get from the sitemap to an actual html page listed there, but am not sure whether this will make it not spiderable or any other problems with doing that.

Dubbya
05-12-2008, 11:06 AM
Absolutely!

How's that for a great answer!!!

It's easy as pie too.

GSiteCrawler (http://gsitecrawler.com/en/download/) will spider your site, generate a sitemap file and a gss.xsl stylesheet automatically.

chandrika
05-12-2008, 12:20 PM
That is a great answer and would you believe it, I already have that program, I just obviously didnt read the manual properly and see what it could do! This will make my life easier, as I had just figured I needed an xsl stylesheet, but my experiments with them were not going too well.

Thanks

Dubbya
05-12-2008, 01:10 PM
You should be good to go. As long as your server supports xsl documents, you should just need to upload it and you'll be off to the races.

jawn_tech
05-12-2008, 05:04 PM
If you're hand-coding, your code could look something like this:


<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="chandrikastylesheet.css"?>

chandrika
05-12-2008, 05:27 PM
Can you use css to turn an xlm element into a link?

such as where you have
<LOC>somepageonasite.com</LOC>

Can you use css to turn that into a clickable link, or would you have to use xls to do that?

Somewhere some code needs to be written with the href tag being inserted, and I couldnt see how that could be done with css.

hemalshah
05-13-2008, 12:14 AM
hey,

is it possible the CSS file attaching with google xml sitemap?

if possible then pls anyone explain how is it? (with code)

Dubbya
05-13-2008, 02:11 AM
You can check out how to write your own XSLT Style sheets using these tutes:

XML.com: Style-free XSLT Style Sheets (http://www.xml.com/pub/a/2000/07/26/xslt/xsltstyle.html)

XSLT Tutorial (http://www.w3schools.com/Xsl/default.asp)

This page shows how to pull the data from the xml file and format it into tables or simply push the data back to the browser:

TopXML : XSL Stylesheets - HTML (http://www.topxml.com/xsltStylesheets/xslt_html.asp)

Scroll down to "LinksPull1, LinksPull2 or LinksPush1 to find the information you'll need to print out hyperlinks.

BTW, as you write it back to the browser, you can style it using CSS attributes.

This page from IBM WebSphere should give you the information you need to get going with incorporating CSS into your XSL file:
Improve your XSLT coding five ways (http://www.ibm.com/developerworks/library/x-xslt5.html)

Good Luck

chandrika
05-13-2008, 05:11 AM
Thanks Dubya, I appreciated the first reply, but it is good to know how to do it by hand. I hadnt been able to find any good tutorials on the subject.

Hemalshah, I think you are trying to do what I wanted too, as it is my google sitemap that I am trying to format here.

I have a site where my xml sitemaps get more traffic than my homepage, so really wanted for it to be properly linked to the main site. It may be beacuse my sitemap files have a .php extension, they are xml, but the xml is written by a php script.

Anyway, I needed to do something with them and I think the xls is the answer. Its new to me, but very interesting and useful to know about with many applications.

wige
05-13-2008, 09:38 AM
I have done something similar one one of my test domains, taking an entire web site of XML documents and using XSLT to convert the pages into web pages. If you want to see a practical working example, you can check out the site at TicketWarehouse.us (http://www.ticketwarehouse.us). Although it is not an actual sitemap, if follows the same basic principles.

The first step is to add the link to the XSLT stylesheet in the sitemap itself:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://url.of/stylesheet.xsl" type="text/xsl" ?>
<urlset (http://www.sitemaps.org/protocol.php#urlsetdef) xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url (http://www.sitemaps.org/protocol.php#urldef)>
<loc (http://www.sitemaps.org/protocol.php#locdef)>http://www.example.com/</loc>
<lastmod (http://www.sitemaps.org/protocol.php#lastmoddef)>2005-01-01</lastmod>
<changefreq (http://www.sitemaps.org/protocol.php#changefreqdef)>monthly</changefreq>
<priority (http://www.sitemaps.org/protocol.php#prioritydef)>0.8</priority>
</url>
</urlset>
The next step is to create the stylesheet itself. First, lay out the page you want the user to display in your favorite HTML editor. The code must be in HTML Strict, so that it can be put into the XSLT file, which is an XML document. The code must be fully standards compliant, as any errors could break the template. You should also keep the template as simple as possible. A very very basic XSLT file would be as follows:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<html>
<head>
<title>Sitemap</title>
</head>
<body>
<h1>My Site Map</h1>
</body>
</html>

You will note the above code does not actually do anything with the data in the site map yet. That is the next step. First, you need to determine what elements you want converted into links. In an XML sitemap, links are stored in the <urlset> section, with each link represented by a <url> tag. However, since there is no title or description associated with these entries, all you could give the user is a long list of URLs, which link to your various pages. Use the following code (inserted after the </h1> tag in the code above) to list all of the URLs as links:


<xsl:template match="/urlset">
<xsl:for-each select="url">
<p>
<a href="{loc}">
<xsl:value-of select="loc" />
</a>
</p>
</xsl:for-each>
</xsl:template>

What this code snippet does is, if the XML file contains an element called "urlset", for each element within called "url", display the "loc" element as a link.

ron angel
05-13-2008, 11:37 AM
Absolutely!

How's that for a great answer!!!

It's easy as pie too.

GSiteCrawler (http://gsitecrawler.com/en/download/) will spider your site, generate a sitemap file and a gss.xsl stylesheet automatically.

Thanks for this post gsitecrawler is the best program of its type I have seen. always best to check the file produced instead of using the auto ftp upload in case there maybe a duplicate file in the site map if you have the knowledge to do so. this is the site map of my site made by program, viewable in browser so no need for html ver on site!
http://www.ssrichardmontgomery.com/sitemap.xml

chandrika
05-13-2008, 01:08 PM
That looks good ron angel, thanks for showing the results from gsitecrawler and thanks Wige for explaining how to use the xsl, I am going to get my head around using it, as there are all sorts of thing I am thinking it will be really useful for. Being able to format xml files into html that way, all sorts of exciting possibilities.

I am thinking is this used for mobile sites as well? I had been meaning to look into designing for mobiles and have a feeling this is something to do with that. I bought a few .mobi domains, and have never got round to developing them yet.

wige
05-13-2008, 01:46 PM
This won't work with mobile sites effectively. That was my goal with the .us site I mentioned, using XSLT to serve different templates based on platform. I have not been able to find any mobile web browser that will parse XSLT reliably. Even Opera does not acknowledge that this is a supported feature of their mobile browser. Internet Explorer and Opera also have a different implementation of XSLT than Firefox, which can cause issues if you want to use multiple style sheets.