Solved

need to transform xml into visual sitemap

Posted on 2011-02-15
6
1,031 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
Comment Utility
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
Comment Utility
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
Comment Utility
Gertone,

I think I have the ASP fixed, but no data is being displayed.
Will this XSL run using the MSXML 6 processor?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP and Soap 3 25
C# SQL BULK INSERT CLASS 5 32
Flexbox in CSS3 2 23
SVG Logo 4 16
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now