[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

make three columns instead of one

Posted on 2011-02-21
7
Medium Priority
?
333 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
ID: 34944539
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
ID: 34944757
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
ID: 34944785
yes, these errors would go away with a different namespace
(at least when the validator supports sitemap extensions, most will)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:TrueBlue
ID: 34945056
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
ID: 34945639
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
ID: 34946548
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 2000 total points
ID: 34946987
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

873 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