Solved

need to transform xml into visual sitemap

Posted on 2011-02-15
6
1,061 Views
Last Modified: 2012-05-11
Hi!

Any specific code would be appreciated in converting XML sitemap into visual HTML sitemap.
I guess XSLT would be the best way.
http://www.topsecurityinc.com/sitemap.xml
0
Comment
Question by:TrueBlue
  • 3
  • 3
6 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34901762
This is all the XSLT you need
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="1.0">
    <xsl:output method="html" indent="yes"/>
    <xsl:strip-space elements="*"/>
<xsl:template match="urlset">
    <html>
        <body>
            <xsl:apply-templates select="url">
                <xsl:sort select="priority" order="descending" data-type="text"/>
            </xsl:apply-templates>
        </body>
    </html>
</xsl:template>
    <xsl:template match="url">
        <p>
             <a href="{loc}">
                <xsl:value-of select="loc"/>
            </a>
        </p>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:TrueBlue
ID: 34902696
Gertone,
Thank you for the XSLT.
Any idea why this is not displaying anything?

<%
      Dim NewXML, re, oXmlSrc, oXml, oNode, oXslSrc, oXsl, oXslTemplate
      
      ' If you're using an XSLTemplate and XSLProcessor object,
      '   you have to use the FreeThreaded versions of DOMDocument
      Set oXmlSrc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
      Call oXmlSrc.setProperty("ServerHTTPRequest", True)            
      oXmlSrc.async = False
      
      Set oXslSrc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
      Call oXslSrc.setProperty("ServerHTTPRequest", True)            
      oXslSrc.async = False
      
      Set oXslTemplate = Server.CreateObject("MSXML2.XSLTemplate.4.0")

      ' If I haven't posted the form first, then load my unaltered XML.
      ' If I'm posting info to resort or edit, then build my XML from that.
      
    ' On Error Resume Next  'debugging code if table does not appear uncomment this line

      'xmlResponse = Replace(xmlResponse, "<?xml version=""1.0""?>", "<?xml version=""1.0"" encoding=""utf-8""?>")

            'Call oXmlSrc.loadXML (xmlResponse)      
            Call oXmlSrc.load (Server.MapPath("sitemap.xml"))
          'Response.Write "<xmp>" & oXmlSrc.xml & "</xmp>"    'debugging code
          'newXML = oXmlSrc.xml
        'Set re = new regexp
        're.pattern = " xmlns.+?>"
        'newXML = re.replace(newXML,">")
        'Call oXmlSrc.loadXML(newXML)
  if oXslsrc.load (Server.MapPath("sitemap.xsl")) then
     Set oXslTemplate.stylesheet = oXslsrc
     Set oXslProcessor = oXslTemplate.createProcessor()
     oXslProcessor.input = oXmlsrc
     Response.Write oXmlsrc
    else
       Response.Write "Could Not Retrieve SiteMap.xsl stylesheet"
end if %>
0
 

Author Comment

by:TrueBlue
ID: 34920837
Gertone,

I think I have the ASP fixed, but no data is being displayed.
Will this XSL run using the MSXML 6 processor?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34921784
THis will run fine on any XSLT processor.
msxml6 will be fine, but make sure you have msxml6 isntalled, since you point to it directly

I don't like this
    'xmlResponse = Replace(xmlResponse, "<?xml version=""1.0""?>", "<?xml version=""1.0"" encoding=""utf-8""?>")
there is no need to add UTF_8 there since it is teh default
and you seem to cast an xml object to a string

you might need some debugging since you need to check wheiter XSLT and XML are all loaded correctly

and of course, I don't know whether your XML sitemap has a namespace
0
 

Author Comment

by:TrueBlue
ID: 34922077
Gertone,

I think I fixed most of the aforementioned items you, except for the namespace.
http://www.topsecurityinc.com/sitemap.xml
Any suggestions as to the proper namespace for this xml page?
TIA
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 34923746
yeah, did not spot the nemaespace in that source before

here you go
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9"
   version="1.0">
    <xsl:output method="html" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="sm:urlset">
        <html>
            <body>
                <xsl:apply-templates select="sm:url">
                    <xsl:sort select="sm:priority" order="descending" data-type="text"/>
                </xsl:apply-templates>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="sm:url">
        <p>
            <a href="{sm:loc}">
                <xsl:value-of select="sm:loc"/>
            </a>
        </p>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question