Solved

Missing hypertext text

Posted on 2011-02-19
3
393 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
  • 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

20 Experts available now in Live!

Get 1:1 Help Now