0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

WOW. So simple. Sorry about the lack of input and context. But your intuition has served you well. Spot on. Many thanks. Will accept as an answer as soon as it allows me to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.