SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I use XSL to create a sitemap.xml?

    Hi I have a custom XML file which shows the structure of my website.

    It is useful for showing navigation, A-Z, sitemap pages and centralising other information like metadata. An extract is shown here:

    Code:
    <item>
      <title>Home</title>
      <link>index.php</link>
      <keywords>Keywords for home page</keywords>
      <description>Decription for home page</description>
      <dateCreated>Tues, 28 Nov 2008 16:00:00 GMT</dateCreated>
      <dateModified>Tues, 28 Nov 2008 16:00:00 GMT</dateModified>  
    </item>
    I have called this file sitemap.xml. However it isn't in the format required by Google http://www.sitemaps.org/protocol.php (because I needed to add in extra stuff like metadata).

    I was wondering can I add a stylesheet to sitemaps.xml e.g.

    Code:
    <?xml-stylesheet type="text/xsl" href="search_engine_sitemap.xsl"?>
    And reformat sitemap.xml using this XSL:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" />
    
    <xsl:template match="/">
      <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">    
        <url>
         <loc>
           <xsl:apply-templates select="/items//item" />
         </loc>
        </url>
      </urlset>
        
    </xsl:template>
    
    <xsl:template match="item">
      http://wwww.open.ac.uk/disability/<xsl:value-of select="link"/>
    </xsl:template>
    
    </xsl:stylesheet>

  2. #2
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, that won't work. The XSL is just changing how it looks. You need the XML to be correct.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any idea how I could reformat this page to have the correct XML?

    Maybe extract the information I need using PHP and write a new file or something?

    Thanks

  4. #4
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do you generate the sitemap now? Can't you just modify that script? If it's static then you can just insert it manually.

  5. #5
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The sitemap I produce is HTML embedded in a php page (using XML and XSL) using this code:

    [code]

    // display sitemap
    function sitemap() {
    // define the XSL
    $load_xsl = 'xml/sitemap.xsl';

    // load XML and XSL files
    load_XML($load_xsl);
    }

    // load XML and XSL files
    function load_XML($load_xsl) {
    // work out the page name
    $this_page = get_page();

    // load the XML
    $xml = new DOMDocument;
    $xml->load('xml/sitemap.xml');
    $xsl = new DOMDocument;

    // load the XSL
    $xsl->load($load_xsl);

    // configure the transformer
    $proc = new XSLTProcessor;
    $proc->setParameter('', 'this_page', $this_page);
    $proc->importStyleSheet($xsl); // attach the xsl rules
    echo $proc->transformToXML($xml);
    }

    [code]

    However what I need to do is output a new XML file called sitemap.xml in the correct format.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •