Skip to content

Will I See You at M3Conf?


One week from now, October 25th, the second edition of the midwestern US conference on mobile app development, M3Conf, will begin. It will be a two-day event, starting with half and full day sessions taught by regional industry luminaries. The second day, which is the main conference day, will consist of two keynote speakers and five one hour sessions. You can see the full schedule at www.m3conf.com.

The conference will be held at the Ohio State University’s student union building, which is a newly built and fantastically furnished place. The best part is that there will be WiFi available all through the building!

I will be delivering a talk entitled “Your First Enterprise App – From the Trenches” at 9:15am on the main conference day (October 26th). There are still some tickets left for the main conference day and are only $100 (a complete steal for the value), so I hope to see you there. Please stop by my talk, chat with me a bit, and ask plenty of questions.

How to Handle Heavily Nested XML Tags with XSLT


I’m new to using Extensible Stylesheet Language Transformations (XSLT). Because I’m new and I had a fairly complex (or so I thought) task to perform with XSLT, I was confused at first.

The task I had and, consequently, the issue that was tripping me up, was with transforming heavily nested tags in my source XML file. Here’s an example of the type of XML I’m talking about.

<?xml version="1.0" encoding="UTF-8"?>
<tag1>
  <tag1>
    <tag1>
      <tag1>
        <arbitrary></arbitrary>
        <tag2>
          <tag2>
            <tag1>
              <texttag></texttag>
            </tag1>
          </tag2>
        </tag2>
      </tag1>
    </tag1>
  </tag1>
</tag1>

The gist of this example is that tag1 and tag2 can be nested within each other to arbitrary depths.  At any level of this hierarchy, there can exist other various tags.

The task I had was to transform the XML above to the following:

<?xml version="1.0" encoding="UTF-8"?>
<tag_start/>
  <tag_start/>
    <tag_start/>
      <tag_start/>
        <arbitrary></arbitrary>
        <tag2_start/>
          <tag2_start/>
            <tag1_start/>
              <texttag></texttag>
            <tag1_end/>
          <tag2_end/>
        <tag2_end/>
      <tag1_end/>
    <tag1_end/>
  <tag1_end/>
<tag1_end/>

A little bit of an odd format, but that was, nonetheless, the requirement. The structure is basically the same as before except that there are explicit tags for the start and the end of the tag (for tag1 and tag2) and all other tags placement and content are preserved.

Because of the oddball structure, this seems like an immensely difficult task at first. I went down a lot of paths with my XSLT that tried to do what amounted to a recursive approach in programming, which never worked. It turned out that I misunderstood how an XSLT engine works. I finally stumbled on a great explanation on Stack Overflow that helped: http://stackoverflow.com/a/6199369.

With that explanation in hand, I was able to write this XSLT file to do the transformation:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>

    <xsl:template match="//tag1" >
       <tag1_start/>
       <xsl:apply-templates/>
       <tag1_end/>
    </xsl:template>
    
    <xsl:template match="//tag2">
       <tag2_start/>
       <xsl:apply-templates/>
       <tag2_end/>
    </xsl:template>
  
    
    <!-- 
         standard copy template, this copies all nodes 
         and attributes from the original to the transformed XML.
     -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template> 

</xsl:stylesheet>

I really can’t state things better than the Stack Overflow user did, so I won’t try. Hopefully, if you’re having a similar problem, you will find this post and it will help cajole you into finding a solution.


Mashed Code Magazine

It’s that time of the year when software developers, mostly in Ohio, Michigan and the surrounding states but all throughout the country too, start getting ready for CodeMash. The call for talk abstracts has already opened and runs through September 15th and the conference organizers are now also taking on sponsors. So if you are endowed with either the talent and desire to speak at CodeMash or the capital to help underwrite it, we encourage you to do so, heartily. Otherwise, all of you eager would-be attendees (you know it’s going to be a mad rush at registration again) can get ready by watching the suite of videos from the 2012 conference that have been uploaded to InfoQ.

If you go looking on InfoQ for the videos you might have a little trouble being sure that you’ve found them all. Unfortunately, the site does not provide a…

View original post 152 more words


Mashed Code Magazine

The Summer issue is ready and, as always, this issue is free!

Obtaining the issue can be anywhere from a benign act to a feat of sheer geekery. Here are the methods at your disposal and the geek point boost you get for using each one:

+0 – Novice

Just click on a link….this one.

+10 – Novice, with account setup skills

Go to MagCloud to get the PDF as a download or on your iPad (with the MagCloud iPad app). Print versions are also available at MagCloud for $12.99.

+100 – Hip Git User

git clone https://github.com/mashedcodemag/issues

+1000 – Command Line Fu Master

wget --no-check-certificate --progress=bar \
https://github.com/mashedcodemag/issues/zipball/master \
--output-document=mcm-june-2012.zip

We sincerely hope that you enjoy the magazine and find it useful. If you have any comments or questions, or want to report errata, comment below or send an email to mashedcodemag@gmail.com.

View original post

New home for Mashed Code Magazine


My pet project, Mashed Code Magazine, is now a WordPress blog! You can visit mashedcodemagazine.com to check it out. The next issue of the magazine will be out in the next few weeks, so subscribe to the blog or check back soon to get the next issue for free.