Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

need to transform xml into visual sitemap

Posted on 2011-02-15
6
Medium Priority
?
1,144 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

772 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