XML Parsing

I'm trying to parse some xml from a sitemap.xml file using the ASP.NET Site map control.  By default the ASP.NET Sitemap control parses the file using the node names as the output for the control however I'd like to parse the node values as the output.  The control allows you to add a customs XPATH Expression as well as an xsl.xslt file.

What is the XSL/XSLT and/or XPATH that I should use to get at the values of the nodes within the URL Node? Any help appreciated.  

BEGIN XML SITEMAP FILE====================
<?xml version="1.0" encoding="UTF-8"?>
<urlset>
      <url>
            <loc>http://www.thetrend.org/</loc>
            <lastmod>2010-04-21T15:25:16+00:00</lastmod>
            <priority>1.00</priority>
            <changefreq>daily</changefreq>
      </url>
      <url>
            <loc>http://www.thetrend.org/events/</loc>
            <lastmod>2010-04-22T15:25:16+00:00</lastmod>
            <priority>1.00</priority>
            <changefreq>daily</changefreq>
      </url>
      <url>
            <loc>http://www.thetrend.org/news/</loc>
            <lastmod>2010-04-22T15:25:16+00:00</lastmod>
            <priority>1.00</priority>
            <changefreq>daily</changefreq>
      </url>
      <url>
            <loc>http://www.thetrend.org/faqs/</loc>
            <lastmod>2010-04-22T15:25:16+00:00</lastmod>
            <priority>1.00</priority>
            <changefreq>daily</changefreq>
      </url>
</urlset>
END XML SITEMAP FILE======================

I used this for XSLT but doesn't work:

BEGIN XSLT FILE===========================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>URL</th>
        <th>Last Modification Date</th>
      </tr>
      <xsl:for-each select="urlset/url">
        <tr>
          <td><xsl:attribute name="loc"/></td>
          <td>
            <xsl:attribute name="changefreq"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
END XSLT FILE==============================================
kvigorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
<td><xsl:attribute name="loc"/></td>

should be

<td><xsl:value-of select="loc"/></td>
0
Geert BormansInformation ArchitectCommented:
It is a nicer programming style if you used apply-templates instead of for-each
This fits the model for XSLT better, and is easier to maintain in the long end
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="/">
        <html>
            <body>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>URL</th>
                        <th>Last Modification Date</th>
                    </tr>
                    <xsl:apply-templates select="urlset/url"/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="url">
        <tr>
            <td><xsl:value-of select="loc"/></td>
            <td><xsl:value-of select="changefreq"/></td>
        </tr>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
halfbloodprinceCommented:
Try doing this:

Dim objXMLDoc As New XmlDocument
        objXMLDoc.Load("SiteMap.xml") ' Replace this with your file path else it will throw file not found exception
        For Each objXMLNode As XmlNode In objXMLDoc.SelectSingleNode("//urlset/url/loc")
            Dim strResult As String = ""
            strResult = objXMLNode.InnerText
        Next
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

kvigorAuthor Commented:
halfbloodprince,

C# syntax issue... can do exactly the same however,  I see a different syntax on asp.net for my XSL I'll try and use that.
0
kvigorAuthor Commented:
halfbloodprince,

C# syntax issue...CANT do exactly the same however,  I see a different syntax on asp.net for my XSL I'll try and use that.
0
kvigorAuthor Commented:
@Gertone

The XSL you posted still doesn't spit our the values just the td's,  I wonder is this because I'm using the treeview control?  I know we're telling the treeview to take the "value-of" but it's still just outputting the the node name instead of it's value?   e.g.

Skip Navigation Links.
html
--body
---table
----tr
-----th
-----th
-------tr
-------td
-------td
      
-------tr
-------td
-------td
      
-------tr
-------td
-------td
      
-------tr
-------td
-------td

-------tr
-------td
-------td      
      
continues like this...
      
      
      
0
Geert BormansInformation ArchitectCommented:
The result of applying my stylesheet on your source XML is this

So you likely make something go lost because of the CSS or treeview.
<html>
   <body>
      <table border="1">
         <tr bgcolor="#9acd32">
            <th>URL</th>
            <th>Last Modification Date</th>
         </tr>
         <tr>
            <td>http://www.thetrend.org/</td>
            <td>daily</td>
         </tr>
         <tr>
            <td>http://www.thetrend.org/events/</td>
            <td>daily</td>
         </tr>
         <tr>
            <td>http://www.thetrend.org/news/</td>
            <td>daily</td>
         </tr>
         <tr>
            <td>http://www.thetrend.org/faqs/</td>
            <td>daily</td>
         </tr>
      </table>
   </body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kvigorAuthor Commented:
Hmmm...

 The treeview displays the following: view image,I know that's the right format, but the wrong values, so it has to be something what I'm still researching to find out.
XSL-Issue.png
0
Geert BormansInformation ArchitectCommented:
what treeview is that?
the XSLT is tested (even with the .net XSLT processor to be sure)
So I don't understand why you don't get values.
Did you accidently not clear the XSLT cache?
0
kvigorAuthor Commented:
This Treview was generated from the Treeview Control from the Tools Panel under Navigation in Visual Studio.  I clicked the option to configure the Datasource I selected the XML Doc, and I Selected the XSL Doc to style/transform it which doesn't render correctly.

What I did find,  was that if I use the "Xml Control" and point to the XML and XSL files, all renders perfectly.  At this point I'm not sure what I need to do to massage to get the Treeview to render correctly, but I have what I need working so far with the Xml Control.

Thanks Gertone.

XSL-Issue2.png
0
kvigorAuthor Commented:
The solution worked but not with the control I wanted but thanks for finding error in my XSLT.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.