Solved

make three columns instead of one

Posted on 2011-02-21
7
296 Views
Last Modified: 2012-05-11
Hi!

We are using the below listed XSLT to display our XML sitemap.
We have alot of links, so we think it would be easier to read if there were three columns.
Any specific modifications so that the XSLT would display these links in three columns (in a grid if possible) instead of one would be greatly appreciated.

<?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:alt" order="ascending" 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:alt"/>
            </a>
        </p>
    </xsl:template>
</xsl:stylesheet>
0
Comment
Question by:TrueBlue
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
Try this

I removed the ordering because that would make things substantially more difficult.
Let me know if the sorting is crucial
<?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:param name="num-of-cols" select="3"/>
    <xsl:template match="sm:urlset">
        <html>
            <body>
                <table border="1">
                    <xsl:apply-templates select="sm:url[position() mod $num-of-cols = 1]"/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="sm:url">
        <tr>
            <xsl:for-each select="self::sm:url | following-sibling::sm:url[position() &lt; $num-of-cols]">
                <td>
                    <a href="{sm:loc}">
                        <xsl:value-of select="sm:alt"/>
                    </a>
                </td>
            </xsl:for-each>
        </tr>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:TrueBlue
Comment Utility
Gertone,

I know you mentioned that the alt tag was not strict XSLT.
Google webtools gave an error like below for each occurence of the alt tag in our XML sitemap page:
Invalid XML tag
This tag was not recognized. Please fix it and resubmit. Parent tag: url
Tag: alt

Would these errors go away by using the namespace method you suggested?
TIA
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
yes, these errors would go away with a different namespace
(at least when the validator supports sitemap extensions, most will)
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:TrueBlue
Comment Utility
Gertone,

Apparently Google does not support sitemap extensions because I tried the method with a different namespace and Google gives the same errors.
Does everyone have to maintain two sitemaps?
One for search engines and one for users.
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
I don't know actually, I never worked with XML sitemaps before and I must say that I was shocked to find out that a sidemap has no way of adding user friendly information to it.
I started reading into this and yes, xml sitemaps are meant for search engines only, not for human consumption.

No, you don't need to maintain two sitemaps.
I would recommend to make one sitemap as you did, but filter out the alt field
You can use the XSLT we worked on so far to create the HTML three column sitemap

You can use the XSLT that I include with this message for generating the google xml sitemap
(assuming you did not put the alt in a different namespace

All from your one source sitemap

Hope this helps
<?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="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"></xsl:apply-templates>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="sm:alt"/>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:TrueBlue
Comment Utility
Gertone,

First, thank you for your exceelent help.
Are you saying have two xslt files?
If so, currently I call only one from the XML page.
So how would I know which one to call?
TIA
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
Comment Utility
Yes, two XSLT files indeed
The first one we worked on can be used to create the html sitemap from your master sitemap
The second one can be used to generate the xml sitemap from the master sitemap
(the master sitemap being the xml sitemap plus extension)

the first XSLT you call when the html sitemap is requested
the second XSLT is called when the xml sitemap is requested
basically instead of statically serving /sitemap.xml, make sure that you have some code that generates that /sitemap.xml on request
(or run the second XSLT from time to time when you need to change the sitemap.xml because the master sitemap had changed)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

10 Experts available now in Live!

Get 1:1 Help Now