7 articles and counting

XSLT, Widgets and MailTo Links Oh MY!

(Ok, so this’ll be short but it’s something that I had a mental hangup on the other day.  After I finally figured it out I thought – I should blog that…)

I’ve never really used XSLT as much as I should have been favoring instead to consume XML data using flash, however recently I’ve moved away from a lot of what I was doing in flash in favor of using simple AJAX using the Microsoft AJAX Toolkit for nothing more than expediance of development, etc…  (I am by no means a proponent of AJAX over Flash or FLEX for RIA’s however that’s a blog for another day. Though yes, I am one of those developers who LOVES SWF content and thinks that AJAX is a day late and a dollar short.)

The other day I was working on an FLEX Based RIA that uses a .NET middle tier and I had the need for some XSLT magic.   

First, some background intel on the application just to set the mood. 

The application is comprised of content pages that are comprised of widgets that are comprised of data items that are comprised of XML data.   Each widget has a type that defines how the data item’s XML data is rendered.  There are chart widgets, metric widges, table widgets and mixed content widgets – the Flex UI knows how to handle each type and renders itself accordingly.  Mixed content widgets are widgets that don’t have a defined set or style of content and are meant as catch-alls for any content not already handled by the other widget types. 

Since the mixed contents are catch-alls and can potentially display anything I chose to use XSLT to render their data and since Flex can render a subset of standard HTML this works quite well.   (Though it would great if FLEX would natively support the full set of standard HTML – c’mon Adobe!)   When the web service receives a request from a data item an XML result packet containing the data to be  rendered is passed back.  Mixed content widget data is transformed inside the service and standard HTML is handed back in <CDATA> tags, Flex picks up the HTML and renders the widget – and whamo all is right with the world.

SO, all that to get to this.  I needed to hand back a MailTO: link as part of a result packet and the XSLT to create one was not what I expected.

<xsl:when test="EMAIL!= ''">
            <u>
              <a>
                <xsl:attribute name="href">
                  mailto:<xsl:value-of select="EMAIL"/>
                </xsl:attribute>
                <xsl:value-of select="USER_NAME"/>
              </a>
            </u>
</xsl:when>

The weird part for me was the following line:

<xsl:attribute name="href">

I kept struggling with the quotes that would need to hug the href and value parts of the  mailto, however the solution ended up not being a matter of escaping quote characters – it was just a matter of using XSLT the way it wanted to be used.

So that was it, a small mental hangup that ended up having a simple solution that I thought might help someone else. 

Happy coding!

Leave a Reply

Name (required)
Mail (will not be published) (required)

Your Comments:

Spam Protection by WP-SpamFree