Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 228113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:39:18+00:00 2026-05-11T19:39:18+00:00

I have a xml doc with around 150 entries. I am sorting the entries

  • 0

I have a xml doc with around 150 entries. I am sorting the entries in several fashions. One is alphabetical, which is displayed via XSLT and works perfectly, the others are by category and solution, which have issues with alternating banding color by row.

The problem arises when I iterate over entries that are not being displayed, it seems that they are being included in the count even though they are not being displayed. I asked this question once before under an anonymous user, hopefully I am clearer this time.

Thanks for the help.

XML Doc.

<case-studies>
    <!-- #### X #### -->
    <case-study>    
        <name>Entry 1</name>
        <category solution="Performance">Medical</category>
        <category solution="Medical">Security</category>
        <category solution="Industry">Medical</category>
        <category solution="A-Z">X</category>
    </case-study>

<!-- #### Y #### -->
    <case-study>    
        <name>Entry 2</name>
        <category solution="Industry">Education</category>
        <category solution="Convergence">Education</category>
        <category solution="A-Z">Y</category>
    </case-study>

</case-studies>

XSLT Call

    <%
        Dim mm_xsl As MM.XSLTransform = new MM.XSLTransform()
        mm_xsl.setXML(Server.MapPath("/data/xml/case-studies/case-studiesTest.xml"))
        mm_xsl.setXSL(Server.MapPath("/data/xslt/case-studies/categoryLandingOther.xsl"))
        mm_xsl.addParameter("solName", "Industry")
        mm_xsl.addParameter("catName", "Business services")
        Response.write(mm_xsl.Transform())
    %>

Portion of xslt

<xsl:for-each select="case-studies/case-study/category[. = $catName]">     

    <!--xsl:sort select="../name" /-->
    <xsl:if test="@solution[. = $solName]">


        <tr>
        <xsl:if test="(position() mod 2 = 1)">
            <xsl:attribute name="bgcolor">#e7e7e7</xsl:attribute>                
        </xsl:if>    
          <td class="cell1">                
          </td> 
          <td class="cell2" style="padding-top:2px;">» <a href="{../url}"><xsl:value-of select="../name"/></a></td>
          <td class="cell3">
            <xsl:for-each select="../solutionType">         
                <div class="clearRight"><xsl:value-of select="."/></div>
            </xsl:for-each>                
          </td>
        </tr>

    </xsl:if>
</xsl:for-each>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:39:18+00:00Added an answer on May 11, 2026 at 7:39 pm

    First: Try to avoid <xsl:for-each>. It’s a bad choice most of the time.

    Second: Select only those nodes that you want to output and your row alternation will work:

    <xsl:template match="/case-studies">
      <xsl:apply-templates select="case-study[
        category = $catName 
        and
        category/@solution = $solName
      ]">
        <xsl:sort select="name" />
      </xsl:apply-templates>
    </xsl:template>
    
    <xsl:template match="case-study">
      <tr>
        <xsl:if test="position() mod 2 = 1"> 
          <xsl:attribute name="bgcolor">#e7e7e7</xsl:attribute>
        </xsl:if>    
        <td class="cell1" />                
        <td class="cell2" style="padding-top:2px;">
          <xsl:text>» </xsl:text>
          <a href="{url}"><xsl:value-of select="name"/></a>
        </td>
        <td class="cell3">
          <xsl:apply-templates select="solutionType" />
        </td>
      </tr>
    </xsl:template>
    
    <xsl:template match="solutionType">
      <div class="clearRight">
        <xsl:value-of select="."/>
      </div>
    </xsl:template>
    

    Edit:

    You can use an <xsl:key> to speed up the selection process, but this will only have a positive effect if you query the same data repeatedly during the same transformation process.

    <xsl:key name="kCaseStudy" 
             match="case-study" 
             use="concat(category, category/@solution)" 
    />
    
    <!-- no need to be in "/case-studies" context this time -->
    <xsl:template match="/">
      <xsl:apply-templates select="key('kCaseStudy', concat($catName, $solName))">
        <xsl:sort select="name" />
      </xsl:apply-templates>
    </xsl:template>
    
    <!-- ... code that uses "key('kCaseStudy', ...)" again ... -->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have xml that looks like this: <Doc> <Thing> <ID type=One>Fred</ID> </Thing> <Thing> <ID>Bill</ID>
My head is fuzzled with this. I have an xml doc which has the
I have function which accepts string (which is basically a XML doc). I am
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have XML in the following format which I want to reformat: <blocks> <!--
I have an xml doc defined as <Body>Stuff stuff stuff <FormatStuff> alsdkfafkafkaf </FormatStuff> </Body>
So I have this XML doc: <?xml version=1.0 encoding=UTF-8?> <Root> <Item> <URL>http://www.mysite.com/page?id=1</URL> </Item> </Root>
I have several xml files whose postfix is not .xml, but .component Now I
I have a xml doc as below. <data> <employee> <moretag> may or may not
Suppose I this have this XML doc, where ... just represents other miscellaneous nodes:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.