Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6594465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:48:54+00:00 2026-05-25T17:48:54+00:00

I’m relatively new to XSL and am attempting to elegantly transform a Google Calendar

  • 0

I’m relatively new to XSL and am attempting to elegantly transform a Google Calendar feed into something more readable.

I would appreciate your eyes on whether there are optimizations to be made. In particular, I would like your advice on template use. I’ve read a lot about how for-each is not appropriate to use willy-nilly (rather, one should attempt to make judicious use of templates).

Thank you very much.

Original XML (showing only one event):

<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gCal='http://schemas.google.com/gCal/2005' xmlns:gd='http://schemas.google.com/g/2005'>
    <id>http://www.google.com/calendar/feeds/bachya1208%40gmail.com/public/full</id>
    <updated>2011-09-19T21:32:50.000Z</updated>
    <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'/>
    <title type='text'>John Doe</title>
    <subtitle type='text'>John Doe</subtitle>
    <link rel='alternate' type='text/html' href='https://www.google.com/calendar/embed?src=bachya1208@gmail.com'/>
    <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://www.google.com/calendar/feeds/johndoe%40gmail.com/public/full'/>
    <link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='https://www.google.com/calendar/feeds/johndoe%40gmail.com/public/full/batch'/>
    <link rel='self' type='application/atom+xml' href='https://www.google.com/calendar/feeds/johndoe%40gmail.com/public/full?max-results=25'/>
    <link rel='next' type='application/atom+xml' href='https://www.google.com/calendar/feeds/johndoe%40gmail.com/public/full?start-index=26&amp;max-results=25'/>
    <author>
        <name>John Doe</name>
        <email>johndoe@gmail.com</email>
    </author>
    <generator version='1.0' uri='http://www.google.com/calendar'>Google Calendar</generator>
    <openSearch:totalResults>1334</openSearch:totalResults>
    <openSearch:startIndex>1</openSearch:startIndex>
    <openSearch:itemsPerPage>25</openSearch:itemsPerPage>
    <gCal:timezone value='America/Denver'/>
    <gCal:timesCleaned value='0'/>
    <entry>
        <id>http://www.google.com/calendar/feeds/johndoe%40gmail.com/public/full/lp0upnpndnkp0ruqht7ef84kds</id>
        <published>2011-09-14T21:15:16.000Z</published>
        <updated>2011-09-14T21:15:16.000Z</updated>
        <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'/>
        <title type='text'>Oil Change</title>
        <content type='text'/>
        <link rel='alternate' type='text/html' href='https://www.google.com/calendar/event?eid=bHAwdXBucG5kbmtwMHJ1cWh0N2VmODRrZHMgYmFjaHlhMTIwOEBt' title='alternate'/>
        <link rel='self' type='application/atom+xml' href='https://www.google.com/calendar/feeds/johndoe%40gmail.com/public/full/lp0upnpndnkp0ruqht7ef84kds'/>
        <author>
            <name>John Doe</name>
            <email>johndoe@gmail.com</email>
        </author>
        <gd:comments>
            <gd:feedLink href='https://www.google.com/calendar/feeds/johndoe%40gmail.com/public/full/lp0upnpndnkp0ruqht7ef84kds/comments'/>
        </gd:comments>
        <gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'/>
        <gd:where valueString='9955 E Arapahoe Road, Englewood, CO 80112 (Go Subaru Arapahoe)'/>
        <gd:who email='johndoe@gmail.com' rel='http://schemas.google.com/g/2005#event.organizer' valueString='bachya1208@gmail.com'/>
        <gd:when endTime='2011-09-29T11:30:00.000-06:00' startTime='2011-09-29T10:30:00.000-06:00'/>
        <gd:transparency value='http://schemas.google.com/g/2005#event.opaque'/>
        <gCal:anyoneCanAddSelf value='false'/>
        <gCal:guestsCanInviteOthers value='true'/>
        <gCal:guestsCanModify value='false'/>
        <gCal:guestsCanSeeGuests value='true'/>
        <gCal:sequence value='0'/>
        <gCal:uid value='lp0upnpndnkp0ruqht7ef84kds@google.com'/>
    </entry>
</feed>

XSLT:

<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
    <xsl:template name="formatDateTime">
        <xsl:param name="dateTime" />
        <xsl:value-of select="concat(substring-before($dateTime, 'T'), ' ', substring-before(substring-after($dateTime, 'T'), '.'))" />
    </xsl:template>
    <xsl:template match="/">
        <Events>
            <xsl:apply-templates select="/*/*[local-name()= 'entry']" />
        </Events>
    </xsl:template>
    <xsl:template match="*[local-name()= 'entry']">
        <xsl:variable name="startDateTime" select="*[name() = 'gd:when']/@*[local-name() = 'startTime']" />
        <xsl:variable name="endDateTime" select="*[name() = 'gd:when']/@*[local-name() = 'endTime']" />
        <Event>
            <EventTitle>
                <xsl:value-of select="*[local-name() = 'title'][1]" />
            </EventTitle>
            <StartDateTime>
                <xsl:call-template name="formatDateTime">
                    <xsl:with-param name="dateTime" select="$startDateTime" />
                </xsl:call-template>
            </StartDateTime>
            <EndDateTime>
                <xsl:call-template name="formatDateTime">
                    <xsl:with-param name="dateTime" select="$endDateTime" />
                </xsl:call-template>
            </EndDateTime>
            <Who>
                <xsl:value-of select="*[local-name() = 'author']/*[local-name() = 'name']" />
            </Who>
            <Where>
                <xsl:value-of select="*[name() = 'gd:where']/@*[local-name() = 'valueString']" />
            </Where>
            <Status>
                <xsl:value-of select="*[name() = 'gd:eventStatus']/@*[local-name() = 'value']" />
            </Status>
        </Event>
    </xsl:template>
</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-16"?>
<Events>
    <Event>
        <EventTitle>Oil Change</EventTitle>
        <StartDateTime>2011-09-29 10:30:00</StartDateTime>
        <EndDateTime>2011-09-29 11:30:00</EndDateTime>
        <Who>John Doe</Who>
        <Where>9955 E Arapahoe Road, Englewood, CO 80112 (Go Subaru Arapahoe)</Where>
        <Status>http://schemas.google.com/g/2005#event.confirmed</Status>
    </Event>
</Events>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:48:55+00:00Added an answer on May 25, 2026 at 5:48 pm

    Your approach looks fine to me. I think your XPath code would be much cleaner and would probably run faster if you used regular element selection instead of local-name. The reason you probably struggled with your XPath was because you’re consuming XML that has a default namespace of http://www.w3.org/2005/Atom, and that namespace isn’t declared in your stylesheet. Here’s a snippet of how a more simplified stylesheet could look, using an f: prefix for the feed namespace:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:f="http://www.w3.org/2005/Atom"
                    xmlns:gd="http://schemas.google.com/g/2005">
    
      <!-- ... -->
    
      <xsl:template match="/">
        <Events>
            <xsl:apply-templates select="//f:entry" />
        </Events>
      </xsl:template>
    
      <xsl:template match="f:entry">
        <xsl:variable name="startDateTime" select="gd:when/@startTime" />
        <xsl:variable name="endDateTime" select="gd:when/@endTime" />
        <Event>
            <EventTitle>
                <xsl:value-of select="f:title[1]" />
            </EventTitle>
            <StartDateTime>
                <xsl:call-template name="formatDateTime">
                    <xsl:with-param name="dateTime" select="$startDateTime" />
                </xsl:call-template>
            </StartDateTime>
            <EndDateTime>
                <xsl:call-template name="formatDateTime">
                    <xsl:with-param name="dateTime" select="$endDateTime" />
                </xsl:call-template>
            </EndDateTime>
            <Who>
                <xsl:value-of select="f:author/f:name" />
            </Who>
            <Where>
                <xsl:value-of select="gd:where/@valueString" />
            </Where>
            <Status>
                <xsl:value-of select="gd:eventStatus/@value" />
            </Status>
        </Event>
      </xsl:template>
    
      <!-- etc -->
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.