XSLT template

Aug 20, 2010 at 4:49 PM

I'd like to help with your project if I can. Just wondering if it makes sense to try for an XSLT transformation rather than developing a "template" style with String.Format placeholders?

Aug 20, 2010 at 5:04 PM

Here's what I'm suggesting. This is just a quick prototype so I'm sure it can be refactored.

<xsl:template match="control">
<xsl:choose>
<xsl:when test="@controlTypeID='com.balsamiq.mockups::CallOut'">
<xsl:call-template name="button"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="button">
<!--
<Button Width="{Width}" Height="{Height}" Margin="{X},{Y},0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
-->
<xsl:element name="Button">
<xsl:attribute name="Width"><xsl:value-of select="@measuredW"/></xsl:attribute>
<xsl:attribute name="Height"><xsl:value-of select="@measuredH"/></xsl:attribute>
<xsl:attribute name="Margin"><xsl:value-of select="concat(@x, ',', @y, ',0,0')"/></xsl:attribute>
<xsl:attribute name="HorizontalAlignment">Left</xsl:attribute>
<xsl:attribute name="VerticalAlignment">Top</xsl:attribute>
</xsl:element>
</xsl:template>

 

[Input]

<mockup version="1.0" skin="sketch" measuredW="941" measuredH="169" mockupW="36" mockupH="40">
  <controls>
    <control controlID="1" controlTypeID="com.balsamiq.mockups::CallOut" x="644" y="129" w="-1" h="-1"
             measuredW="36" measuredH="40" zOrder="1" locked="false" isInGroup="-1">
      <controlProperties>
        <text>Hello!</text>
        <backgroundAlpha>0.25</backgroundAlpha>
        <color>65280</color>
      </controlProperties>
    </control>
  </controls>
</mockup>

 

[Output]

<?xml version="1.0" encoding="utf-8"?><mockup version="1.0" skin="sketch" measuredW="941" measuredH="169" mockupW="36" mockupH="40">
  <controls>
    <Button Width="36" Height="40" Margin="644,129,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
  </controls>
</mockup>