Jump to content

creating rows limiting members to a certain number.


layton
 Share

Recommended Posts

I know that title sounds a little confusing but I can't think of a proper way of naming it. Here's what I'm looking for and I can't seem to figure out a way to do it.I have an xml document that has say 20 nodes with various sub-nodes. As it stands - I have a a loop that will display all of them vertically, but I'm looking for a way to list them horizontally and then limiting it to 5 items per row. So within the loop I need to be able to tell if it's the fifth node for that row and if so, create a new row.the layout would look something like the following, where each [x] is a separate node.[x] [x] [x] [x] [x][x] [x] [x] [x] [x][x] [x] [x]what I have so far is this:

<xsl:for-each select="team/member[type='member']">	<div class="pfdiv">	  <a href="{pfinderURL}"><img src="{imageURL}" /></a>	  <h4><xsl:value-of select="name" /></h4>	  <xsl:value-of select="mtitle" />	</div>	</xsl:for-each>

Link to comment
Share on other sites

I assume you are floating your divs? What if you tried and if statement like:

<xsl:for-each select="team/member[type='member']">	<div class="pfdiv">	  <a href="{pfinderURL}"><img src="{imageURL}" /></a>	  <h4><xsl:value-of select="name" /></h4>	  <xsl:value-of select="mtitle" />	</div>	<xsl:if test="position() % 5 == 0">	  <br style="clear:both"/>	</xsl:if></xsl:for-each>

I am not great at XSL but I think the theory is sound.

Link to comment
Share on other sites

This question is already answered in the XSLT FAQ, question 5. Perhaps it's my fault that I generalized it too much, but after all, some people want 3 columns, and others want 5. If I say one or the other, it's like eliminating the others.

Link to comment
Share on other sites

This question is already answered in the XSLT FAQ, question 5. Perhaps it's my fault that I generalized it too much, but after all, some people want 3 columns, and others want 5. If I say one or the other, it's like eliminating the others.
The example shows how to do it with a table, using tr, td and the like. I'm looking for a way that doesn't use tables. I can't seem to open a tag, run a loop and run checks, then close the loop when the checks meet the requirements. I just get an error from the browser that it expected a closing tag. I guess I could always go back to tables for this one thing, but I'd rather not.
Link to comment
Share on other sites

I assume you are floating your divs? What if you tried and if statement like:
<xsl:for-each select="team/member[type='member']">	<div class="pfdiv">	  <a href="{pfinderURL}"><img src="{imageURL}" /></a>	  <h4><xsl:value-of select="name" /></h4>	  <xsl:value-of select="mtitle" />	</div>	<xsl:if test="position() % 5 == 0">	  <br style="clear:both"/>	</xsl:if></xsl:for-each>

I am not great at XSL but I think the theory is sound.

Hrm - that's a interesting thought. I could try that. That's basically the theory I was going for but didn't know how to do it. Normally in a loop in a coding environment like JS or PHP, I'm able to open a tag (<div>) and then after my count reaches what i want, I can close it (</div>). XSL just throws an error because the first tag isn't closed right away.
Link to comment
Share on other sites

Hrm - that's a interesting thought. I could try that. That's basically the theory I was going for but didn't know how to do it. Normally in a loop in a coding environment like JS or PHP, I'm able to open a tag (<div>) and then after my count reaches what i want, I can close it (</div>). XSL just throws an error because the first tag isn't closed right away.
The code I gave you will work the same way if you replace the "tr" with a "div" and "td" with whatever you want being repeated. XSLT doesn't care about the nature of the output (HTML) elements.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...