WTF Sandwich
Quote of the Moment Edit this quote!
Posted by Nacho Jerjou :: Jun 12 2007 at 08:32

stfu

--Your Mom in "Your Face"

 

Funny thing, I'm a programmer but this is my first fully nerdy technical this-is-how-I-did-xyz-task post. Go figure.

Anyways, here is some detail about accessing Java classes from within an XSLT stylesheet, so long as you are processing it with Xalan. (For yummy syntax highlighting, here's the post as a Pastie)

The main gist is that any built-in Java class can be accessed by using the 'xalan://java.package.name.ClassName' syntax. It is easiest if you 'import' the classes you need into your stylesheet using a namespace declaration at the top of the file. For example:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:cal="xalan://java.util.GregorianCalendar"
  xmlns:tz="xalan://java.util.TimeZone"
  xmlns:fmt="xalan://java.text.SimpleDateFormat">

  <xsl:template match="/">
    <!-- Stylesheet goodness goes here -->
  </xsl:template>
</xsl:stylesheet>

Then later on in your stylesheet, you can call functions on the class using the defined namespace. In this context, static members (aka 'class functions', such as Calendar.getInstance()) are called simply using the namespace and a colon. Other member functions (such as Calendar.set(int field, int value), which operate on a specific instance), take the instance variable as the first parameter, and all other parameters are shifted (so the first parameter becomes the second, the second the third, etc).

Here's an example of this which parses a string that contains a GMT time and outputs it as a PST:

  <xsl:template name="FormatDate">
    <xsl:param name="date" />
    
    <!-- incoming format: YYYYMMDDTHHMMSSZ -->
    <!-- outbound format: MM/DD/YYYY HH:MM AM -->

    <xsl:variable name="tz_pt" select="tz:getTimeZone('America/Los_Angeles')" />
    <xsl:variable name="tz_utc" select="tz:getTimeZone('UTC')" />
    <xsl:variable name="fmt_in" select="fmt:new(&quot;yyyyMMdd'T'HHmmss&quot;)" />
    <xsl:variable name="fmt_out" select="fmt:new('MM/dd/yyyy HH:mm:ss a')" />

    <!--  Set the output time format to PST, and the input time format to GMT.
          These statements don't actually output anything. -->
    <xsl:value-of select="fmt:setTimeZone($fmt_out, $tz_pt)" />
    <xsl:value-of select="fmt:setTimeZone($fmt_in, $tz_utc)" />

    <xsl:if test="$date != ''">
      <xsl:variable name="src_date" select="fmt:parse($fmt_in, $date)" />
      <xsl:value-of select="fmt:format($fmt_out, $src_date)" />
    </xsl:if>
  </xsl:template>

Note the use of 'xsl:value-of' statements in order to call an instance method on our variables. In XSLT, you have to wrap your method call in a 'select=' type statement, either in a 'xsl:value-of' or as the evaluation of an 'xsl:variable' in order for them to be executed.

You could call this somewhere in your style sheet by selecting the date value you wish to convert.

  <xsl:template match="first_president">
    George Washington was born on <xsl:call-template name="FormatDate">
        <xsl:with-param name="date" select="birth_date"/>
      </xsl:call-template>
  </xsl:template match="first_president">
Add a comment!
 

Looking back, I probably thought that if I didn't blog about it, it would go away.

2009 has not, so far, been kind to Travis Briggs (Travis Briggs' blog, this is the blog of Travis Briggs).

My main problem is that on January 12th, I was laid off from my job. With a conciliatory tone, my boss explained that my work was exemplary, that he was thoroughly impressed with my contributions, but that there simply was no longer room for me at the company. Another developer got cut at the same time as me. It turns out that they let me go exactly on my 2 month 'anniversary'. The most crushing immediate impact of being laid off was that they cut off my health benefits immediately (not at the end of the month). I ended up having to pay over 200 dollars for prescription drugs later that week-- and that was only for a half month's supply! I read through my options, and COBRA would cost me like 415 dollars a month, so I should probably get that, seeing that my prescriptions would then only cost 45 dollars and I would be covered for other ailments (at about the same cost as a month of drugs now).

Notice that I introduced the above as being my 'main' problem. Additionally, I have recently turned twenty-four (on the 13th, the day after losing my job). I'll admit there was the passing joy of celebrating the occasion with my family (my mom baked an awesome double-layered peanut butter chocolate cake) and some friends. However it seems the main function of this date was to call into relief the fact that the past 2-3 years have been wasted. I've given up a great job (Brightcove) had multiple failed romantic relationships, failed at saving any money I've earned and barely made a dent in my student loan payments, and failed to accomplish anything significant or worthwhile outside of my professional life, which in itself has not lived up to its full potential. My social circle (friends and acquaintances) has shrunk rather than grown, besides the fact that I am a fat, unemployed computer programmer living in his parents' basement.

Mother. Fucker.

I'm a generally optimistic person, though, and I'm convinced things can get better. Not that they necessarily will-- I know it will take work and dedication and of all things luck on my part-- but that they can. Here's hoping.

..
Posted by Eric Mill :: Feb 05 2009 at 04:52

As someone who's been there for the great and the terrible, I can tell you that my faith in the vast potential of Travis Q. Briggs has not flagged. You remain one of the most creative, energetic, and passionate people I know. You've been given some pretty difficult personal circumstances these last few years -- circumstances that anybody would be bedeviled by.

But you're going to get out of it just fine, and in another 2-3 years, you're going to be looking back on a lot of good times and personal victories. This I believe! And this it shall be.

---------------------------------
..
Posted by Anna T. :: Feb 12 2009 at 00:16

Well said, Eric

---------------------------------
..
Posted by Big Baby Jesus :: Mar 03 2009 at 03:49

but seriously, travis, aren't we all fat, unemployed programmers living in our parents' basement deep down inside?

also, if the programming business starts to get you down, you can always fall back on a career as an improvisational unicycler. word.

Add a comment!
 

He's like the surprise Christmas present that you forgot to open Christmas morning. Tonight, while pondering the awful things going on in Gaza and how completely incompetent and ineffectual our asshole President is, I remembered that the dark knight (ahem) is on his way. It made me really happy, and I'm literally filled with hope that he can do something about this mess and our economic troubles.

Two other things. I'm going to the gym tomorrow (tomorrow!) and I'm signing the fuck up. My fat pants were snug to put on today, and that's just intolerable. I've been fat before, and it makes the second time easier. But getting even fatter than I've ever been, when I've already been pretty fat? No fucking way. NO FUCKING WAY!

I don't even care. I have no life, I can go to the gym every fucking day. All it means is taking a later train home. And I can afford a personal trainer too, to 1) teach me a bunch of fancy-pants exercises and best practices so that I maximize my workout and 2) inspire me to keep a schedule/appointments (harder to blow off the gym when you have an appointment with a trainer).

As for the second thing, I FINALLY bought a book that I've wanted for more than 3 years. It is The Computer Music Tutorial by Curtis Roads. It's basically a textbook for all things computer music. Not just MIDI, Digital Audio Workstation, home-music-production stuff. We're talking synthesis, digital signal processing, etc. Hardcore stuff like you'd learn in Bianchi's classes if he was teaching grad students. I already own The Csound Book, a similarly intimidating tome. However I found The Csound Book to be too application specific, though it was fun to work through some of the tutorials.

Anyways, with the new book, I finally plan on pursuing my dream of programming/creating a virtual analog synthesizer in Audio Unit format. This goal is a bit 'rained on' by my discovery the other day (while doing 6+ hours of research) of Rham which is EXACTLY what I wanted to do. My heart is so broken, I was tempted to use a <blink> tag.

But at least I'm not going to be fat anymore.

Oh and Christmas was nice.

Add a comment!
 

Damn right: http://cowbird.110mb.com/46.html.

Also, I, Travis Briggs am going to spammishly (Travis Briggs) pad this post with my name (which happens to be Travis Briggs) in order to attempt to reclaim my #1 Google spot which seems to be oscillating between Travis Briggs (the real Travis Briggs) and some dork with a livejournal. I'm considering making the front page of my site automatically re-direct to http://www.boxofmonocles.com/travis/briggs/travis-briggs

http://travis-briggs.livejournal.com/
Posted by http://travis-briggs.livejournal.com/ :: Dec 19 2008 at 14:36

I love your livejournal! http://travis-briggs.livejournal.com/ It's full of great facts about your livejournal life! Keep up that livejournal! http://travis-briggs.livejournal.com/

---------------------------------
..
Posted by Carol :: Dec 27 2008 at 19:26

Travis-

Hi there, how are you? It's been many years since I've seen you....please tell Dee and Scott that I've said "hi". They'll know who it is.

Nice blog :)

Add a comment!
 

It's nearly 11 and Thanksgiving is pretty much officially over. I'll admit guiltily that I didn't see any part of the televised Macy's parade, for I woke up at around 12:30 PM.

No matter what happens in my life, I'll always remember the fact that my mother is a cooking MACHINE. She had 3 types of pie ready before I had even woken up, not to mention the extra turkey that she cooked yesterday. There were two separate rounds of appetizers, the latter including stuffed mushrooms and baked stuffed shrimp.

It was my niece Hailey's first Thanksgiving, which was a largely uneventful occasion. She was paraded around to some of her father's (my future brother-in-law's) family. During the meal, she sat in her bouncer seat and watched football, making high-pitched cooing noises (at 5 months, she's still far too young to share).

I also did a little bit of impromptu music recording with my uncle Buddy (who's not really my uncle and not really named Buddy). He plays some mean folk/blues guitar, and I let him play Rosie for a bit. Eventually I plugged him into Pro Tools, and he laid down a track (which he unfortunately messed up a bit, but I'm going to maybe try and fix it up).

The day was without pageantry, without poignancy, but still had a lot of old-fashioned, feel-good charm. My family is good people and we do love each other. And I'm thankful for that.

Add a comment!
 

Friend of a Friend Creative Commons License

This blog and all of its original content is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike2.5 License. All other content is made available under the Fair Use laws of the United States of America.

Contact me through email me using this form.