Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Nov 17, 2009 @ 13:50
    Tim
    1

    Empty class tags

    Hi Tim,

    Nice macro! I noticed that it generates a lot of empty class tags and class tags with extra trailing spaces though. If you dump the class string into a variable and then check if its there before adding the classes, you can eliminate the empty tags (and use the normalise-space function to kill the trailing spaces). Here's the code I used:

    <xsl:variable name="itemClass">
    <xsl:if test="$isSelected = 1"><xsl:value-of select="concat($selectedClass,' ')"/></xsl:if>
      <xsl:if test="$isSelectedBranch = 1"><xsl:value-of select="concat($branchClass,' ')"/></xsl:if>
      <xsl:if test="$hasChildren = 1"><xsl:value-of select="'hasChildren '"/></xsl:if>
    </xsl:variable>

    <xsl:if test="string-length($itemClass) > 0">
    <xsl:attribute name="class">
      <xsl:value-of select="normalize-space($itemClass)"/>
      </xsl:attribute>
    </xsl:if>

    It doesn't seem to impact the performance from the tests I've run, and you get cleaner html output.

  • Tim 225 posts 690 karma points
    Nov 19, 2009 @ 13:49
    Tim
    0

    Hi Tim,

    Thanks for the code, this was definately on my list of things to tidy up. I'll have a look at implementing your approach in the next release.

    Tim

     

  • Isaac Levin 22 posts 42 karma points
    May 10, 2010 @ 16:52
    Isaac Levin
    0

    Tim,

     

    Can you go into a little more detail what you are doing here? I would like to implement this to what I am currently working on. Thanks.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies