Solved

Missing hypertext text

Posted on 2011-02-19
3
436 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 500 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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