0
votes

I'm iterating through a node group using the following:

    <xsl:for-each select="NewDataSet/VehicleDetail/Options/Option">
    <xsl:choose>
        <xsl:when test="string-length(.) > 40">
            <div class="large">
                <xsl:value-of select="."/>
            </div>
        </xsl:when>
        <xsl:otherwise>
            <div class="small">
                <xsl:value-of select="."/>
            </div>
        </xsl:otherwise>
    </xsl:choose>
</xsl:for-each>

What I would like to be able to do is group the large items (40 chars +) and the small items (40 chars and less) something like this:

<div class="largeItems">
  <div class="large">Large Item</div>
  <div class="large">Large Item</div>
  <div class="large">Large Item</div>
  <div class="large">Large Item</div>
  <div class="large">Large Item</div>
</div>
<div class="smallItems">
  <div class="small">Small Item</div>
  <div class="small">Small Item</div>
  <div class="small">Small Item</div>
  <div class="small">Small Item</div>
  <div class="small">Small Item</div>
</div>

Thanks.

1

1 Answers

1
votes

Try:

<div class="largeItems">
    <xsl:for-each select="NewDataSet/VehicleDetail/Options/Option[string-length() > 40]">
        <div class="large">
            <xsl:value-of select="."/>
        </div>
    </xsl:for-each>
</div>
<div class="smallItems">
    <xsl:for-each select="NewDataSet/VehicleDetail/Options/Option[string-length() &lt;= 40]">
        <div class="small">
            <xsl:value-of select="."/>
        </div>
    </xsl:for-each>
</div>

Or, if you prefer less code duplication:

<div class="largeItems">
    <xsl:apply-templates select="NewDataSet/VehicleDetail/Options/Option[string-length() > 40]">
        <xsl:with-param name="class" select="'large'"/>
    </xsl:apply-templates>
</div>
<div class="smallItems">    
    <xsl:apply-templates select="NewDataSet/VehicleDetail/Options/Option[string-length() > 40]">
        <xsl:with-param name="class" select="'small'"/>
    </xsl:apply-templates>
</div>  

and then:

<xsl:template match="Option">
    <xsl:param name="class"/>
    <div class="{$class}">
        <xsl:value-of select="."/>
    </div>
</xsl:template>

Untested because neither input nor context have been provided.