Solved

make three columns instead of one

Posted on 2011-02-21
7
302 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Viewing XML as a table on a Mac 3 134
XSLT Help 12 33
Excel file not created as expected 7 72
Configure a Bean in an XML file 4 34
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…
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. 
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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