Copied to clipboard

Flag this post as spam?

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


  • Laura Holland 82 posts 103 karma points
    Oct 03, 2011 @ 23:57
    Laura Holland
    0

    Remove final bullet (or comma) from last unordered list item

    I have a horizontal two-level unordered list, with a bullet between each sub item. The list is generated by the following XSLT:

    <xsl:param name="currentPage"/>
      <xsl:variable name="level" select="3"/>
      <xsl:variable name="preIDProduct" select="1085" />
     
      <xsl:template match="/">
        <div id="collectionCategory">
          <h1>
            <xsl:value-of select="$currentPage/@nodeName"/>
          </h1>
        </div>
        <div id="subNav">
          <ul>
            <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
              <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">          
                    <xsl:attribute name="class">selected</xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="@nodeName"/>
                </a>      
                <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
                  /
                  <ul>             
                    <xsl:apply-templates select="umbraco.library:GetPreValues($preIDProduct)/preValue">
                      <xsl:sort select="." data-type="text" order="ascending" />
                      <xsl:with-param name="node" select="current()" />
                    </xsl:apply-templates>
                  </ul>          
              </xsl:if>         
              </li>
            </xsl:for-each>
          </ul>
        </div>
      </xsl:template>

      <xsl:template match="preValue">
        <xsl:param name="node" />
        <xsl:if test="$node/*/productSubType[contains(., current())]">
          <li>
            <a>
              <xsl:attribute name="href" >
                <xsl:value-of select="umbraco.library:NiceUrl($node/@id)"/>
                <xsl:text>/?select=</xsl:text>
                <xsl:value-of select="."/>
              </xsl:attribute>
                <xsl:value-of select="."/>
            </a>
            <xsl:if test="position()!=last()">
              <xml:text disable-output-escaping="yes"> &#183; </xml:text>
            </xsl:if>
          </li>
        </xsl:if>
      </xsl:template>

    I need to remove the bullet after the final item in the list. The test="position()!=last() is not working (I get a bullet on every item, including the last). I'm not sure how to do this type of test because in this particular scenario there is no for-each loop..

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 04, 2011 @ 00:17
    Chriztian Steinmeier
    0

    Hi Laura,

    The problem with this is that it's tecnically working - just not the way we'd like it to...

    When the apply-templates instruction is executed, a nodeset is created (from the nodes matched by the expression in the select attribute) - that nodeset is then "the current node list", which position() values are then based on, and thus the last() function. Problem is, the set you're running through is all the prevalues - go see what the last prevalue in the dropdown is, and check if it gets a bullet where it's used - it most likely won't.

    To get the result you're after, you would need to create a set set of the actual preValues that's in use, which seems to require some sort of grouping, unless we're able to get the usage into the select in the apply-templates instruction.

    EDIT:

    So I've tried a couple of things, which didn't work - but really, are you sure you shouldn't just do this with CSS? When the HTML has been generated, finding the last item is just a :last-child selector away, depending on your browser compatibility requirements...

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft