?
Solved

Missing hypertext text

Posted on 2011-02-19
3
Medium Priority
?
440 Views
Last Modified: 2012-06-27
Hi!

Any specific modifications to the below listed XML / XSLT as to how to recreate the below listed functionality using XML & XSLT?

<A HREF="mywebpage.html">My Web Page</A>

Currently, all of the urls are listed but no custom text like the above "My Web Page".
In other words, I rather have a user friendly text like "About Us" in lieu of
http://www.sample.com/aboutus.html displayed but still have a functionaly hypertext.

Also, do you have to include the domain name as part of the <loc> tag value or just the pagename for a valid sitemap?

Sample: XML

<?xml-stylesheet type="text/xsl" href="sitemap.xsl"?>
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
 <url>
  <loc>http://www.sample.com/mywebpage.html</loc>
  <changefreq>weekly</changefreq>
  <priority>1.00</priority>
  </url>
<url>
  <loc>http://www.sample.com/mynewpage.html</loc>
  <changefreq>weekly</changefreq>
  <priority>1.00</priority>
  </url>
</urlset>

XSLT:

<?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>
0
Comment
Question by:TrueBlue
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34934859
XML sitemap don't have a way for adding a "name" of the relation
So you need to divert from the spec if you want to do that

There is no way creating the
"My New Page"
from
http://www.sample.com/mynewpage.html</loc>
unless you start stuffing full dictionairies in your XSLY

your best bet is to set the named reference as an extra element in the sitemap

<url>
  <loc>http://www.sample.com/mywebpage.html</loc>
  <alt>My Web Page</alt>
  <changefreq>weekly</changefreq>
  <priority>1.00</priority>
  </url>

and in the xslt
          <a href="{sm:loc}">
                <xsl:value-of select="sm:alt"/>
            </a>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34934883
Actually to do what I just suggested, it would be more correct to use the sitemap.org extension mechanism
(using a different namespace)


<?xml-stylesheet type="text/xsl" href="sitemap.xsl"?>
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:trueblue="http://www.trueblue.org/sitemap/extensions" 
         xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
 <url>
  <loc>http://www.sample.com/mywebpage.html</loc>
  <trueblue:alt>My Web Page</trueblue:alt>
  <changefreq>weekly</changefreq>
  <priority>1.00</priority>
  </url>
<url>

Open in new window

0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 34934890
and make th eappropriate changes to the stylesheet as well


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:trueblue="http://www.trueblue.org/sitemap/extensions" 
    xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9"
   version="1.0">
...
        <a href="{sm:loc}">
                <xsl:value-of select="trueblue:alt"/>
            </a>

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

764 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