Copied to clipboard

Flag this post as spam?

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


  • stc 72 posts 101 karma points
    Sep 30, 2010 @ 16:06
    stc
    0

    Change div tag's attribute based on position()

     

    Hi guys,

      I'm sorry but I gotta ask you this...is there an easy and elegant way to write this..a not closed/closing div tag whose attribute needs to be changed if it is the first or not:

                    <xsl:if test="position()&lt;= $noOfItems">
            <xsl:choose>
                <xsl:when test="position()&lt;= 1">
                <div class="slide first">
                </xsl:when>
                <xsl:otherwise>
                <div class="slide">
                </xsl:otherwise>
            </xsl:choose>

    Since the div inside is not self-closing, in fact it has a big deal of html inside, I wouldn't want to use the xsl:attribute and then put all of that html after attribute assigning construct...TIA

     

    P.S.

    Is SQL CE 4 umbraco version coming soon?

     

  • Magnus Eriksson 122 posts 362 karma points
    Sep 30, 2010 @ 16:11
    Magnus Eriksson
    1

    This should do it:

      <div>
        <xsl:choose>
          <xsl:when test="position()&lt;= 1">
            <xsl:attribute name="class">slide first</xsl:attribute>
          </xsl:when>
          <xsl:otherwise>
            <xsl:attribute name="class">slide</xsl:attribute>
          </xsl:otherwise>
        </xsl:choose>
        inside div code...
      </div>

    Regards,
    Magnus

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 30, 2010 @ 16:16
    Chriztian Steinmeier
    1

    You can get even shorter:

    <div class="slide">
        <xsl:if test="position() &lt;= 1">
            <xsl:attribute name="class">slide first</xsl:attribute>
        </xsl:if>
        ...
    </div>

     

    /Chriztian

  • stc 72 posts 101 karma points
    Oct 01, 2010 @ 10:31
    stc
    0

    Thanks guys...it's just I was trying to avoid the "inside div code..." part...since that's massive.

    Oh well, indenting with tabs is no more an option.

     

  • Magnus Eriksson 122 posts 362 karma points
    Oct 01, 2010 @ 10:53
    Magnus Eriksson
    1

    I don't really understand the problem, could you elaborate? I don't get why this won't work for you...

    <div class="slide">
            <xsl:if test="position() &lt;= 1">
                    <xsl:attribute name="class">slide first</xsl:attribute>
            </xsl:if>
            Massive bit of HTML
    </div>

    Is the problem that you have dublicate instances of the code? Then maybe you should be refactoring your xslt to use more templates (call-template, apply-templates)?

  • stc 72 posts 101 karma points
    Oct 01, 2010 @ 13:28
    stc
    0

    Hi Magnus,

      It will work, I high fived for it, however I was hoping there could be some other attribute value assign mechanism in XSLT...since I'm an XSLT n00b...thus call-template, apply-templates are a bit over my head for now, though I wrote a couple of those by example.

      Will look into those within xsl:for-each contrsuct just as soon as I can.

      Thanks all the same though.

Please Sign in or register to post replies

Write your reply to:

Draft