473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

XSLT count items?

The code below puts each item in a float:left DIV. After each 3rd DIV it needs to clear the previous 3 DIVs and start a new row. The code below works, but it requires that I edit a 'column' element in my XML file. Every 3rd item in my XML file has a <column>3</column> element added to it so the xsl:if test code knows when to add my clearing DIV.

This seems inefficient to me and I'm sure there is a way the XSLT processor can insert my <div class="cleardiv"/> after each 3rd item. Any ideas?


Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="item"> 
  2.  
  3.      <div class="leftcolumn33">
  4.  
  5.  
  6. <!--Display Title and Description-->    
  7.     <h2><xsl:value-of select="title"/></h2>
  8.     <p><xsl:copy-of select="description/node()"/></p>
  9. <!--END Display-->                
  10.  
  11.  
  12.      </div> <!--End leftcolumn33 div-->
  13.  
  14.  
  15. <!--Test if the value in 'column' element is 3.  If so, add a 'cleardiv'-->
  16.      <xsl:if test="column ='3'"> 
  17.           <div class="cleardiv"/>
  18.      </xsl:if>
  19. <!--END Test-->
  20.  
  21.  
  22. </xsl:template>
Dec 28 '08 #1
4 4548
Dormilich
8,658 Expert Mod 8TB
a quick idea (without testing)......

if position() % 3 = 0

try the modulo operator on the position number (if the description elements are siblings), otherwise I'd need a look at the XML

sorry for not having much time
Dec 28 '08 #2
OK...here is the XML code as requested.


Expand|Select|Wrap|Line Numbers
  1. <item id="443476-MZF"> 
  2.      <column>1</column> 
  3.      <title>This is a title</title>
  4.      <description>This is a description</description>
  5. </item>
  6.  
  7. <item id="443477-MZF"> 
  8.      <column>2</column> 
  9.      <title>This is a title</title>
  10.      <description>This is a description</description>
  11. </item>
  12.  
  13. <item id="443478-MZF"> 
  14.      <column>3</column> 
  15.      <title>This is a title</title>
  16.      <description>This is a description</description>
  17. </item>
  18.  
  19. <item id="443479-MZF"> 
  20.      <column>1</column> 
  21.      <title>This is a title</title>
  22.      <description>This is a description</description>
  23. </item>
  24.  
  25. <item id="443480-MZF"> 
  26.      <column>2</column> 
  27.      <title>This is a title</title>
  28.      <description>This is a description</description>
  29. </item>
Dec 28 '08 #3
Thanks for the push in the right direction. I found that it would not accept the mod operator and I had to actually use the word 'mod' in my code. Thanks again...

Here is what worked:

Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="position() mod 3 = 0">
  2. <div class="cleardiv"/>
  3. </xsl:if>
Dec 28 '08 #4
Dormilich
8,658 Expert Mod 8TB
I'm glad that such a little push yielded such a success. ;-)
Dec 28 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
6
by: Per Jørgen Vigdal | last post by:
I have a XML that I need to map. The XML goes like: <Children> <Child> <References> <External> <Reference name="filename" value="1.dat"/> <Reference name="invoicenr" value="1111111"/>...
11
by: ned786 | last post by:
Hello, I'm trying to solve an XSLT problem, and I'm hoping someone can give a little guidance. I am transforming XML to HTML. Here's an example of the XML file I'm dealing with, greatly...
4
by: dar_imiro | last post by:
Hi, I'm trying to get rid of frames as menu holder in my html-page. I'd also like to separate the menu structure to xml and xslt. Also the actual content is divided to xml and its corresponding...
1
by: jrwarwick | last post by:
Hello, I believe I have uncovered a bug in the .Net XSLT engine to do with 'for' loops in XSLT. Here are the steps to reproduce it: -Create A new webform project. -Add the xml file...
4
by: J | last post by:
I've spent most of the day on this, and I just can't seem to find a solution, please help me! :) I'm recieving XML that I can't modify that looks like: <?xml version="1.0"?> <Doc> <Page>...
4
by: bobiron | last post by:
Hi, any ideas to improve the above ugly and not efficient code? Thanks Roberto <!-- source XML NOTE: elements "col" changes from source to source --> <?xml version="1.0"?> <resultset>...
2
by: Adam dR. | last post by:
I have an xml file similar to: <menu> <menuitem name="home" show="false"/> <menuitem name="about" show="true"/> <menuitem name="links" show="true"/> <menuitem name="games" show="true"/>...
10
by: olivier.scalbert | last post by:
Hello, the following constraints: source: <Source> <Item>AAA</Item> <Item>BBBBBBBBBBB</Item> <Item>CCCCCCCCC</Item> <Item>DDDDDDDDDDDDDDD</Item>
4
by: raghunandanbasf | last post by:
Hi friends, I am new to the xslt when i am doing ,I have struck in middle. Q.As per example:we are having the xml structure like this <a> <b>-----</b> <c>-----</c> <d>-----</d> </a>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.