I recently had the need to output a SELECT HTML element with a list of states. My initial approach was simple where I used
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
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="com.thebitguru" exclude-result-prefixes="custom"> <xsl:output method="html" omit-xml-declaration="yes"/> <xsl:strip-space elements="*" /> <custom:states> <option value="AL">Alabama</option> <!-- ... --> <option value="WI">Wisconsin</option> <option value="WY">Wyoming</option> </custom:states> <xsl:template match="option"> <xsl:copy> <xsl:if test="@value = $val"> <xsl:attribute name="selected">selected</xsl:attribute> </xsl:if> <xsl:attribute name="value"><xsl:value-of select="@value" /></xsl:attribute> <xsl:value-of select="." /> </xsl:copy> </xsl:template> <xsl:template match="*"> <label for="state">* State:</label> <select name="state" id="state"> <xsl:apply-templates select="document('')/*/custom:states/option" /> </select> </xsl:template> </xsl:stylesheet>
The problem with this approach was that the
option tags were printing the xml namespaces, even with the
exclude-result-prefixes="custom" specified (because that attribute does not apply to
1 2 3 4
<option value="AL" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="com.thebitguru">Alabama</option> ... <option value="WI" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="com.thebitguru">Wisconsin</option> <option value="WY" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="com.thebitguru">Wyoming</option>
I didn’t want these namespaces in the output so after some searching and reading through the docs I decided to create new elements using the
<xsl:element> tags instead, especially since the tag that I was copying was very small.
1 2 3 4 5 6 7 8 9
<xsl:template match="option"> <xsl:element name="option"> <xsl:if test="@value = $val"> <xsl:attribute name="selected">selected</xsl:attribute> </xsl:if> <xsl:attribute name="value"><xsl:value-of select="@value" /></xsl:attribute> <xsl:value-of select="." /> </xsl:element> </xsl:template>
There are other ways to accomplish the same thing, e.g. copy-namespaces in XSLT 2.0, but in my case I was stuck with XSLT 1.0.Read more
I recently had the need to cleanup a long diff file and move certain lines to the end of the file for further analysis. The diff file that I got was something like the following, only much longer (produced using
diff -qr xxx yyy).
Files xxx/abc1 and yyy/abc1 differ Only in xxx: cde1 Files xxx/abc3 and yyy/abc3 differ Files xxx/abc4 and yyy/abc4 differ Only in xxx: cde2 Only in xxx: cde5 Files xxx/abc5 and yyy/abc5 differ Only in xxx: cde3
I didn’t care as much about the “Only…” lines, but the files that differed needed more attention. To accomplish this I wanted to get this file in the following format.
Only in xxx: cde1 Only in xxx: cde2 Only in xxx: cde5 Only in xxx: cde3 Files xxx/abc1 and yyy/abc1 differ Files xxx/abc3 and yyy/abc3 differ Files xxx/abc4 and yyy/abc4 differ Files xxx/abc5 and yyy/abc5 differ
I could go in and copy and paste all the lines that matched, but that would be a lot of manual work. So, I looked around for a minute and came up with the following command.
Vim is awesome!Read more
My original patch possibly worked only with OS X 10.6.5. Last night I figured out a better way to apply the patch without relying on a pre-supplied diff. What this means is that starting with version 0.7 the patch should work with pretty much all versions.
If you are interested, check it out on the project page.Read more
I just published a new patch for OS X, below is a description of the patch. Check it out.
This is a patch for removing the default OS X behavior of always starting iTunes when the play button on the keyboard is pressed. This feature can be useful for a lot of users, but it can also be annoying if you are using VLC or other similar programs that support the media keys.
The Patch script will patch the Remote Control Daemon to prevent it from starting iTunes whenever you press the play button on the keyboard or an external remote control. This will only prevent iTunes from starting, all other functions (like play/pause while iTunes is running) will continue to work as before.
Lastly, this program will backup the original file in case if you would like to restore the original functionality.
For more information please visit the Play Button iTunes Patch page.Read more
One thing I have missed in OS X is a powerful media player like MediaMonkey. iTunes gets a good part of the job done, but doesn’t have everything that I need. Plus, I hate the fact that it doesn’t display the ratings that I have on the files from my Windows machine. So, I have been exploring my options and one possibility is Songbird. It it better, but still lacks in some places (once again, ratings). I am still playing around with Songbird because, compared to iTunes, it is a lot easier to create add-ins for Songbird.
The first thing that I noticed missing from Songbird was the ability to delete songs that are not “managed” by Songbird. This is pretty much how iTunes behaves as well. I did not like this because I like control. If I added a file to a playlist then I would also like to have the ability to delete it from both the playlist and the file system.
So, instead of using the prescribed “1-start rating” to denote deletions I decided to explore Songbird extension development. I am glad to report that I was able to figure out the framework and actually just published an extension in the official repository to do just that: Delete from Disk. If you are a Songbird user looking for this functionality then you don’t need to look any further. Browse to the extensions page in Songbird and search for Delete from Disk.
Now let’s figure out what we can do about the ratings…! I also wish that someone will fix the Apple media key support extension.Read more
Lately I have noticed that I kept getting a 400 bad request when doing django development (i.e. using runserver) and browsing through Google Chrome. It was only Chrome that was behaving this way because Firefox would browse without generating any of these errors on the server side.
1 2 3 4
[09/Nov/2010 00:31:53] "GET /acq/ HTTP/1.1" 200 1393 [09/Nov/2010 00:31:53] code 400, message Bad request syntax ('\x16\x03\x00...') ?????????...." 400 -???8 .....????? [09/Nov/2010 00:33:39] "GET /acq/ HTTP/1.1" 200 1393
I finally took a few minutes to debug. After clearing the cache and browsing data as suggested by many sites and having no luck I started disabling all of the extensions that I had installed. Guess what? The error disappeared.
This issue was being caused by the Secure Sites extension which lets you use secure versions of the site if one is available. In order to figure out whether a secure version is available it does an extra request, and it is this extra request that was causing the problem.
What’s the solution? I went into the options for this extension and added localhost to “Assumed no secure version exists” and the error disappeared.Read more
I just published an updated version of the Wake on LAN (WoL) client for webOS (Palm Pre and Pixi). The latest version supports specifying a custom hostname and port, which means that now you can send WoL packages from to a remote network.
James Knowles (please see the about screen for contact info) contributed the initial UI changes for specifying a hostname. I added some more information and added the ability to specify a custom port (which required a service update).
To get these changes please update to/install the latest version of the service and UI using Preware.Read more