Question

XSL: Date/Month format display and sorting

Asked by: baxleyb

Hello,

I have an XML file that contains a number of links that need to be listed and displayed by year, month and then day.

I need an XSL file that can display the data from the XML file like this:

2008

January

1/13/2008 My URL
1/25/2008 My URL
1/31/2008 My URL

March

3/5/2008  My URL
3/10/2008 My URL
3/29/2008 My URL

<hr>------------------------------------------------------------------</hr>

2007

January

1/13/2007 My URL
1/25/2007 My URL
1/31/2007 My URL

March

3/5/2007  My URL
3/10/2007 My URL
3/29/2007 My URL

October

10/6/2007  My URL
10/13/2007 My URL
10/31/2007 My URL
-----------------------------------------------------------------
See the XML code snippet and the XSL code Snippet below.

Any assistance would be greatly appreciated!

XML CODE:
 
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0" xmlns:myCompany="http://www.mycompany.com">
<channel>
<title>My Company News</title>
<link>http://www.MyCompany.com</link>
<description>My Company Corporation</description>
<language>en-us</language>
<pubDate>Tue, 11 Dec 2007 18:00:43 UTC</pubDate>
<docs>http://www.mycompany.com/rss</docs>
<generator>My Company</generator>
<item>
<title>Drought Conditions Worsen  Mandatory Water Restrictions Needed</title>
<link>http://www.mycompany.com/topics/releases/2007082701.php</link>
<description>Extreme drought conditions and record-breaking heat have resulted in the need for mandatory air restrictions.</description>
<pubDate>Mon, 27 Aug 2007 04:00:00 UTC</pubDate>
<myCompany:shortDate>8/27/2007</myCompany:shortDate>
<myCompany:moneyRelease>no</myCompany:moneyRelease>
<guid>http://www.mycompany.com/topics/releases/2007082701.php</guid>
</item>
<item>
<title>My Company CEO Says New York Can Become a Crossroads for Trinkets</title>
<link>http://www.mycompany.com/topics/releases/2007103101.php</link>
<description>The following are excerpts from a speech My Company Chairman, President and CWO Bob Bojangles gave today to the Broke Club of Nowhere in Nowhere's land.</description>
<pubDate>Wed, 31 Oct 2007 04:00:00 UTC</pubDate>
<myCompany:shortDate>10/31/2007</myCompany:shortDate>
<myCompany:moneyRelease>no</myCompany:moneyRelease>
<guid>http://www.mycompany.com/topics/releases/2007103101.php</guid>
</item>
<item>
<title>My Company Reports Third-Quarter 2053 Results</title>
<link>http://www.mycompany.com/topics/releases/2007110201f.php</link>
<description>My Company today reported we are broke and not making any money.</description>
<pubDate>Fri, 2 Nov 2007 04:00:00 UTC</pubDate>
<myCompany:shortDate>11/2/2007</myCompany:shortDate>
<myCompany:moneyRelease>yes</myCompany:moneyRelease>
<guid>http://www.mycompany.com/topics/releases/2007110201f.php</guid>
</item>
<item>
<title>My Company Names Two New Directors; Declares Quarterly Dividend</title>
<link>http://www.mycompany.com/topics/releases/2007102502.php</link>
<description>My Company announced that its board of directors increased its size from 10 to 12 members with the election today of Frick and Frack.</description>
<pubDate>Thu, 25 Oct 2007 04:00:00 UTC</pubDate>
<myCompany:shortDate>10/25/2007</myCompany:shortDate>
<myCompany:moneyRelease>no</myCompany:moneyRelease>
<guid>http://www.mycompany.com/topics/releases/2007102502.php</guid>
</item>
<item>
<title>My Company Names Two New Directors; Declares Quarterly Dividend-06</title>
<link>http://www.mycompany.com/topics/releases/2007102502.php</link>
<description>My Company announced that its board of directors increased its size from 10 to 12 members with the election today of Frick and Frack.</description>
<pubDate>Thu, 20 Oct 2006 04:00:00 UTC</pubDate>
<myCompany:shortDate>10/20/2006</myCompany:shortDate>
<myCompany:moneyRelease>no</myCompany:moneyRelease>
<guid>http://www.mycompany.com/topics/releases/2007102502.php</guid>
</item>
<item>
<title>My Company Names Two New Directors; Declares Quarterly Dividend-99</title>
<link>http://www.mycompany.com/topics/releases/2007102502.php</link>
<description>My Company announced that its board of directors increased its size from 10 to 12 members with the election today of Frick and Frack.</description>
<pubDate>Mon, 6 Apr 1999 04:00:00 UTC</pubDate>
<myCompany:shortDate>4/6/1999</myCompany:shortDate>
<myCompany:moneyRelease>no</myCompany:moneyRelease>
<guid>http://www.mycompany.com/topics/releases/2007102502.php</guid>
</item>
</channel>
</rss>
---------------------------------------------------------------
XSL CODE I HAVE SO FAR:
---------------------------------------------------------------
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:myCompany="http://www.mycompany.com">
  <xsl:output omit-xml-declaration="yes" standalone="yes" media-type="text/xml" indent="yes"/>
  <xsl:template match="/rss">
  <xsl:for-each select="channel/item">
  	<xsl:sort select="substring(myCompany:shortDate,9,4)"/>
        <div class="date"><xsl:value-of select="myCompany:shortDate"/>
      	</div>
        <div class="headline">
		  <xsl:element name="a">
			<xsl:attribute name="href">
				<xsl:value-of select="link"/>
			</xsl:attribute>
			<xsl:attribute name="title">
				<xsl:value-of select="description"/>
			</xsl:attribute>
					<xsl:if test="contains(substring(myCompany:shortDate,1,2), '/')">
				M-There is a slash in the month
				</xsl:if>
	
				<br /><xsl:if test="contains(substring(myCompany:shortDate,3,2), '/')">
				D-There is a slash in the day
				</xsl:if>
	           </xsl:element>
	</div>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-12-13 at 09:27:51ID23021534
Tags

date

,

xsl

,

sort

,

display

,

month

Topics

Extensible Stylesheet Language Transformation (XSLT)

,

Extensible Markup Language (XML)

Participating Experts
1
Points
500
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Format Date in XSL?
    I'm using XSL to output XML that makes a table of class names, reading and dates. The XSL: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:t...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: GertonePosted on 2007-12-13 at 09:34:45ID: 20465958

you would better use substring-before and substring-after instead of simple substring,
because 10 and 8 (october and August) have different string-lengths

You ould use a key for the sorting and grouping bit

 

by: GertonePosted on 2007-12-13 at 09:40:07ID: 20465984

Here is the first level of grouping
It uses muenchian grouping

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:myCompany="http://www.mycompany.com">
    <xsl:output omit-xml-declaration="yes"  media-type="text/xml" indent="yes"/>
    <xsl:key name="it-yr" match="item" use="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/>
    <xsl:template match="/rss">
        <xsl:for-each select="channel/item[generate-id() = generate-id(key('it-yr', substring-after(substring-after(myCompany:shortDate, '/'), '/'))[1])]">
            <xsl:sort select="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/>
            <h1><xsl:value-of select="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/></h1>
            <div class="date"><xsl:value-of select="myCompany:shortDate"/>
            </div>
            <div class="headline">
                <xsl:element name="a">
                    <xsl:attribute name="href">
                        <xsl:value-of select="link"/>
                    </xsl:attribute>
                    <xsl:attribute name="title">
                        <xsl:value-of select="description"/>
                    </xsl:attribute>
                    <xsl:if test="contains(substring(myCompany:shortDate,1,2), '/')">
                        M-There is a slash in the month
                    </xsl:if>
                   
                    <br /><xsl:if test="contains(substring(myCompany:shortDate,3,2), '/')">
                        D-There is a slash in the day
                    </xsl:if>
                </xsl:element>
            </div>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

 

by: GertonePosted on 2007-12-13 at 10:06:58ID: 20466154

Here is the full grouping

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:myCompany="http://www.mycompany.com">
    <xsl:output omit-xml-declaration="yes"  media-type="text/xml" indent="yes"/>
    <xsl:key name="it-yr" match="item" use="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/>
    <xsl:key name="it-mm" match="item" use="substring-before(myCompany:shortDate, '/')"/>
    <xsl:template match="/rss">
        <xsl:for-each select="channel/item[generate-id() = generate-id(key('it-yr', substring-after(substring-after(myCompany:shortDate, '/'), '/'))[1])]">
            <xsl:sort select="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/>
            <xsl:variable name="yr"><xsl:value-of select="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/></xsl:variable>
            <h1><xsl:value-of select="$yr"/></h1>
           
            <xsl:for-each select="key('it-yr', $yr)[generate-id() = generate-id(key('it-mm', substring-before(myCompany:shortDate, '/') )[substring-after(substring-after(myCompany:shortDate, '/'), '/') = $yr][1])]">
                <xsl:sort select="substring-before(myCompany:shortDate, '/')" data-type="number"/>
                <xsl:variable name="mm" select="substring-before(myCompany:shortDate, '/')"></xsl:variable>
                <h2><xsl:value-of select="$mm"/></h2>
                <xsl:for-each select="key('it-yr', $yr)[substring-before(myCompany:shortDate, '/') = $mm]">
                    <xsl:sort select="substring-before(substring-after(myCompany:shortDate, '/'), '/')"/>
                <div class="date">
                    <xsl:value-of select="myCompany:shortDate"/>
                </div>
                <div class="headline">
                    <xsl:element name="a">
                        <xsl:attribute name="href">
                            <xsl:value-of select="link"/>
                        </xsl:attribute>
                        <xsl:attribute name="title">
                            <xsl:value-of select="description"/>
                        </xsl:attribute>
                        <xsl:value-of select="link"/>
                    </xsl:element>
                </div>
                    </xsl:for-each>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

This seems complex at first, since you have to deal with these substring chains for getting the correct part from the datestring
furthermore you have nested muenchian
muenchian is explained very well here

http://www.jenitennison.com/xslt/grouping/muenchian.html

good luck

Geert

 

by: GertonePosted on 2007-12-13 at 10:07:44ID: 20466162

note that you will have to bend the stylesheet to your HTML wishes
add the hr, and put thedates in title fields as pleased

 

by: baxleybPosted on 2007-12-13 at 11:28:07ID: 20466823

FANTASTIC! This is perfect!

1 more question.

How can the month be displayed based on the numeric value:

For example:

4 = April
10 = October

April

4/6/1999     http://www.mycompany.com/topics/releases/200

2006

October

10/20/2006  http://www.mycompany.com/topics/releases/2007102502.p

 

by: GertonePosted on 2007-12-13 at 13:14:17ID: 20467754

That is most easily done using a lookup table
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:myCompany="http://www.mycompany.com"
    xmlns:map="internal" exclude-result-prefixes="map">
    <xsl:output omit-xml-declaration="yes"  media-type="text/xml" indent="yes"/>
    <xsl:key name="it-yr" match="item" use="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/>
    <xsl:key name="it-mm" match="item" use="substring-before(myCompany:shortDate, '/')"/>
    <xsl:template match="/rss">
        <xsl:for-each select="channel/item[generate-id() = generate-id(key('it-yr', substring-after(substring-after(myCompany:shortDate, '/'), '/'))[1])]">
            <xsl:sort select="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/>
            <xsl:variable name="yr"><xsl:value-of select="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/></xsl:variable>
            <h1><xsl:value-of select="$yr"/></h1>
           
            <xsl:for-each select="key('it-yr', $yr)[generate-id() = generate-id(key('it-mm', substring-before(myCompany:shortDate, '/') )[substring-after(substring-after(myCompany:shortDate, '/'), '/') = $yr][1])]">
                <xsl:sort select="substring-before(myCompany:shortDate, '/')" data-type="number"/>
                <xsl:variable name="mm" select="substring-before(myCompany:shortDate, '/')"></xsl:variable>
                <h2><xsl:value-of select="document('')//map:month[@no = $mm]/@name"/></h2>
                <xsl:for-each select="key('it-yr', $yr)[substring-before(myCompany:shortDate, '/') = $mm]">
                    <xsl:sort select="substring-before(substring-after(myCompany:shortDate, '/'), '/')"/>
                <div class="date">
                    <xsl:value-of select="myCompany:shortDate"/>
                </div>
                <div class="headline">
                    <xsl:element name="a">
                        <xsl:attribute name="href">
                            <xsl:value-of select="link"/>
                        </xsl:attribute>
                        <xsl:attribute name="title">
                            <xsl:value-of select="description"/>
                        </xsl:attribute>
                        <xsl:value-of select="link"/>
                    </xsl:element>
                </div>
                    </xsl:for-each>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>
   
    <map:months>
        <map:month no="1" name="January"/>
        <map:month no="2" name="February"/>
        <map:month no="3" name="March"/>
        <map:month no="4" name="April"/>
        <map:month no="5" name="May"/>
        <map:month no="6" name="June"/>
        <map:month no="7" name="July"/>
        <map:month no="8" name="August"/>
        <map:month no="9" name="September"/>
        <map:month no="10" name="October"/>
        <map:month no="11" name="November"/>
        <map:month no="12" name="December"/>
    </map:months>
</xsl:stylesheet>

document('') points to the stylesheet itself
and there you have a lookup table in the map namespace

just make sure that yourprocessor has document('') active,
most of them do but some require explicit ctivation

 

by: baxleybPosted on 2007-12-13 at 13:24:53ID: 20467836

Oh ok, That looks good, but I did this and it worked fine too (see snippet).

What do you think?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:myCompany="http://www.mycompany.com">
    <xsl:output omit-xml-declaration="yes"  media-type="text/xml" indent="yes"/>
    <xsl:key name="it-yr" match="item" use="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/>
    <xsl:key name="it-mm" match="item" use="substring-before(myCompany:shortDate, '/')"/>
    <xsl:template match="/rss">
        <xsl:for-each select="channel/item[generate-id() = generate-id(key('it-yr', substring-after(substring-after(myCompany:shortDate, '/'), '/'))[1])]">
            <xsl:sort select="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/>
            <xsl:variable name="yr"><xsl:value-of select="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/></xsl:variable>
            <h2><xsl:value-of select="$yr"/></h2>
           <hr />
            <xsl:for-each select="key('it-yr', $yr)[generate-id() = generate-id(key('it-mm', substring-before(myCompany:shortDate, '/') )[substring-after(substring-after(myCompany:shortDate, '/'), '/') = $yr][1])]">
                <xsl:sort select="substring-before(myCompany:shortDate, '/')" data-type="number"/>
                <xsl:variable name="mm" select="substring-before(myCompany:shortDate, '/')"></xsl:variable>
                <h4>
<!-- Added this -->
		    <xsl:choose>
		    	<xsl:when test="$mm = '1'">January</xsl:when>
			<xsl:when test="$mm = '2'">February</xsl:when>
			<xsl:when test="$mm = '3'">March</xsl:when>
			<xsl:when test="$mm = '4'">April</xsl:when>
			<xsl:when test="$mm = '5'">May</xsl:when>
			<xsl:when test="$mm = '6'">June</xsl:when>
			<xsl:when test="$mm = '7'">July</xsl:when>
			<xsl:when test="$mm = '8'">August</xsl:when>
			<xsl:when test="$mm = '9'">September</xsl:when>
			<xsl:when test="$mm = '10'">October</xsl:when>
			<xsl:when test="$mm = '11'">November</xsl:when>
			<xsl:when test="$mm = '12'">December</xsl:when>
		    </xsl:choose>
<!-- End here -->
		</h4>
                <xsl:for-each select="key('it-yr', $yr)[substring-before(myCompany:shortDate, '/') = $mm]">
                    <xsl:sort select="substring-before(substring-after(myCompany:shortDate, '/'), '/')"/>
                <div class="date">
                    <xsl:value-of select="myCompany:shortDate"/>
                </div>
                <div class="headline">
                    <xsl:element name="a">
                        <xsl:attribute name="href">
                            <xsl:value-of select="link"/>
                        </xsl:attribute>
                        <xsl:attribute name="title">
                            <xsl:value-of select="description"/>
                        </xsl:attribute>
                        <xsl:value-of select="link"/>
                    </xsl:element>
                </div>
                    </xsl:for-each>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:

Select allOpen in new window

 

by: GertonePosted on 2007-12-13 at 13:29:19ID: 20467869

That will also work fine
The lookup is nicer, since you pull the lookup table outside the code
and it is a bit more XPath like, less procedural
but I would not worry about style at this point in time

 

by: baxleybPosted on 2007-12-14 at 11:11:37ID: 20473740

Hi Gertrone,

One last question.

Is there a way to only display a specific year but in the same format?

For Example, only display all links for 2006?

 

by: GertonePosted on 2007-12-14 at 12:02:05ID: 20474033

I added a global parameter
and the stylesheet now takes the parameter
and copies that particular year

I moved the processing of one year to a named template
so I can add a choice

if I leave the parameter empty,
it will show all years, grouped and sorted

Note that you can feed the value for this parameter in from outside the stylesheet
so you don't need to set the value for $global-year inside the stylesheet

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:myCompany="http://www.mycompany.com">
    <xsl:output omit-xml-declaration="yes"  media-type="text/xml" indent="yes"/>
    <xsl:param name="global-year">2007</xsl:param>
    <xsl:key name="it-yr" match="item" use="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/>
    <xsl:key name="it-mm" match="item" use="substring-before(myCompany:shortDate, '/')"/>
    <xsl:template match="/rss">
        <xsl:choose>
            <xsl:when test="$global-year = ''">
                <xsl:for-each select="channel/item[generate-id() = generate-id(key('it-yr', substring-after(substring-after(myCompany:shortDate, '/'), '/'))[1])]">
                    <xsl:sort select="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/>
                    <xsl:variable name="year"><xsl:value-of select="substring-after(substring-after(myCompany:shortDate, '/'), '/')"/></xsl:variable>
                    <xsl:call-template name="processYear">
                        <xsl:with-param name="yr" select="$year"/>
                    </xsl:call-template>
                </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="processYear">
                    <xsl:with-param name="yr" select="$global-year"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
       
    </xsl:template>
   
    <xsl:template name="processYear">
        <xsl:param name="yr"/>
        <h2><xsl:value-of select="$yr"/></h2>
        <hr />
        <xsl:for-each select="key('it-yr', $yr)[generate-id() = generate-id(key('it-mm', substring-before(myCompany:shortDate, '/') )[substring-after(substring-after(myCompany:shortDate, '/'), '/') = $yr][1])]">
            <xsl:sort select="substring-before(myCompany:shortDate, '/')" data-type="number"/>
            <xsl:variable name="mm" select="substring-before(myCompany:shortDate, '/')"></xsl:variable>
            <h4>
                <!-- Added this -->
                <xsl:choose>
                    <xsl:when test="$mm = '1'">January</xsl:when>
                    <xsl:when test="$mm = '2'">February</xsl:when>
                    <xsl:when test="$mm = '3'">March</xsl:when>
                    <xsl:when test="$mm = '4'">April</xsl:when>
                    <xsl:when test="$mm = '5'">May</xsl:when>
                    <xsl:when test="$mm = '6'">June</xsl:when>
                    <xsl:when test="$mm = '7'">July</xsl:when>
                    <xsl:when test="$mm = '8'">August</xsl:when>
                    <xsl:when test="$mm = '9'">September</xsl:when>
                    <xsl:when test="$mm = '10'">October</xsl:when>
                    <xsl:when test="$mm = '11'">November</xsl:when>
                    <xsl:when test="$mm = '12'">December</xsl:when>
                </xsl:choose>
                <!-- End here -->
            </h4>
            <xsl:for-each select="key('it-yr', $yr)[substring-before(myCompany:shortDate, '/') = $mm]">
                <xsl:sort select="substring-before(substring-after(myCompany:shortDate, '/'), '/')"/>
                <div class="date">
                    <xsl:value-of select="myCompany:shortDate"/>
                </div>
                <div class="headline">
                    <xsl:element name="a">
                        <xsl:attribute name="href">
                            <xsl:value-of select="link"/>
                        </xsl:attribute>
                        <xsl:attribute name="title">
                            <xsl:value-of select="description"/>
                        </xsl:attribute>
                        <xsl:value-of select="link"/>
                    </xsl:element>
                </div>
            </xsl:for-each>
        </xsl:for-each>
       
    </xsl:template>
</xsl:stylesheet>

 

by: baxleybPosted on 2007-12-17 at 08:38:20ID: 20485944

Hi Gertrone,

Thanks for your help thus far.

Is there a way to display the description instead of the URL in the results?

For Example:

THIS
<description>My Company announced that its board of directors increased its size from 10 to 12 members with the election today of Frick and Frack.</description>

INSTEAD OF THIS
<guid>http://www.mycompany.com/topics/releases/2007102502.php</guid>

Thanks.

 

by: baxleybPosted on 2007-12-17 at 08:45:29ID: 20485996

Never mind,

I just changed this:

</xsl:attribute>
                        <xsl:value-of select="link"/>
                    </xsl:element>

to this:

</xsl:attribute>
                        <xsl:value-of select="description"/>
                    </xsl:element>

 

by: baxleybPosted on 2007-12-20 at 08:54:43ID: 20508100

Hi Gertone:

Sorry for the delay.

How could I feed the year into the stylesheet as a parameter?
Would it need to be fed in through another stylesheet or could I feed it in through another scripting language like php or asp?

Thanks.

 

by: GertonePosted on 2007-12-20 at 10:20:30ID: 20508734

since the parameter is global in the stylesheet
  <xsl:param name="global-year">2007</xsl:param>
you can pass a value in from outside

this happens when you call the processor to execute this stylesheet on an XML document.
It all depends on how you do that...
it could be PHP or ASP, JSP, Java
it could as well be from the commandline, or javascript in a browser

tell me how you run the stylesheet now, and I can help you with the next step

cheers

Geert

 

by: baxleybPosted on 2007-12-27 at 11:48:23ID: 20536529

Hi Gertrone,

Thanks for all of your assistance so far.

Basically the XSL is being run through an ASP page.

There is an include file that transforms the xsl (see below)

set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("myXML.xml"))

set MyFILE = Server.CreateObject("Microsoft.XMLDOM")
MyFILE.async = false
MyFILE.load(Server.MapPath(myXSL))


Response.Write(xml.transformNode(MyFILE))

and then the page that actually displays the XSL output is just a variable that prints the XSL (see below)

<%myXSL = "DisplayNews.xsl"%>

So if you know of a way to pass the parameter in, then that would be helpful!

Thanks.

 

by: baxleybPosted on 2008-01-03 at 08:37:51ID: 20574141

Hi Gertrone,

Do you have any suggestions related to my last post on how to pass the year in as a parameter?

Thanks for your help thus far!  :)

 

by: GertonePosted on 2008-01-03 at 09:18:16ID: 20574541

The object you are using is outdated, you should use msxml4 or msxml6 (recommended) instead of msxml3 in "old" mode
I copied from one of my files, so the variable names are different

Set oXML = Server.CreateObject("MSXML2.DOMDocument.6.0")
Set oXSL = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.6.0")

(you could use 4.0, or 3.0, but I don't recommend the 3.0, make sure you got the latest msxml installed)

Since you need a Template processor for passing parameters, you need the XSLT to be free threaded
You also need to declare a template processor

Set oTmpl= Server.CreateObject("Msxml2.XSLTemplate.6.0")

Then you can pass the parameter

oTmpl.stylesheet = oXSL
Set oProc= oTmpl.createProcessor()
oProc.input = oXML
oProc.addParameter "global-year","2007"
oProc.output = Response
oProc.transform()

Hope this helps

Geert





 

by: baxleybPosted on 2008-01-07 at 08:12:53ID: 20600490

Hi Gertone,

I am able to load the XML using the new parser (version 6) but when i try to use this code to display the xsl:

Set oXSL = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.6.0")
Set oTmpl= Server.CreateObject("Msxml2.XSLTemplate.6.0")
oTmpl.stylesheet = oXSL
Set oProc= oTmpl.createProcessor()
oProc.input = oXML
oProc.addParameter "global-year","2007"
oProc.output = Response
oProc.transform()

I get this error:

msxml6.dll error '80004005'

The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.

it is on this line:

oTmpl.stylesheet = oXSL

If I try to load the XSL file like below

oXSL.load(Server.MapPath(strXSL))
oTmpl.stylesheet = oXSL

Then a bunch of weird characters are displayed like this:

ÿþ<ýhý2ý ýxýmýlýnýsý:ýfýoý=ý"ýhýtýtýpý:ý/ý/ýwýwýwý.ýwý

any ideas on this?

 

by: baxleybPosted on 2008-02-11 at 08:48:56ID: 20867794

Hi Gertrone,

Thanks so much for your time and patience. You were very helpful.

 

by: baxleybPosted on 2008-02-11 at 08:49:26ID: 31414805

Gertrone was very helpful.

 

by: GertonePosted on 2008-02-11 at 09:02:19ID: 20867929

welcome

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...