Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: variables >Thread Next - Re: variables Re: variablesTo: NULL Date: 4/2/2007 11:55:00 PM On 30 Mar, 14:54, Martin Honnen <mahotr...@yahoo.de> wrote: > RedLars wrote: > > Say I have a loop which processes some items that each has its unique > > id (for instance; 1,2,5,7,12,25,24,46,78,130 ) > > > <xsl:for-each select="Nodes"> > > <h2><xsl:value-of select="@type"/><xsl:number value="@id" > > format="001"/></h2> > > // code > > </xsl:for-each> > > > I'm struggling with adding a line change (<br>) when the id changes > > from 10's to 20's. So I'd like to have all items with id 0-9 on one > > line and from 10-19 on another line etc. > > As for XSLT and checking the id, use the floor(@id div 10) and compare > to the following-sibling e.g. > > <xsl:for-each select="Node"> > <h2><xsl:value-of select="@type"/><xsl:number value="@id" > format="001"/><xsl:value-of select="concat(' floor: ', floor(@id div > 10))"/></h2> > <xsl:if test="floor(@id div 10) != > floor(following-sibling::node[1]/@id div 10)"> > <br/> > </xsl:if> > </xsl:for-each> > > I don't think however that it is a good idea in terms of HTML structural > markup to separate h2 elements by br elements, h2 is a block element for > a heading, if you want list items then consider ol or ul with li and > suggest formatting like padding and margin with CSS. > > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/ Cheers for the feedback. It's almost working now, just one small problem, the xml data I'm working on is not sorted. By doing <xsl:sort .. I'm able to sort the list but it seems that following.sibling::node()[1] doesn't select the next sorted element but the next element. So for instance when dealing with computer element with number equals 1, it looks to the next sibling element which in the xml file is computer element with number equals 161 and not the element with number equal 2. See the 'problem'? Any ideas? <xsl:for-each select="computer"> <xsl:sort select="@number" data-type="number"/> <a href="#{generate-id()}"><xsl:value-of select="@type"/><xsl:number value="@number" format="001"/></a> <xsl:value-of select="concat(' floor: ', floor(@number div 10))"/> <xsl:value-of select="concat(' floor_sib: ', floor(following- sibling::node()[1]/@number div 10))"/> <xsl:value-of select="concat(' floor_num: ', (following- sibling::node()[1]/@number))"/> <xsl:if test="floor(@number div 10) != floor(following-sibling::node() [1]/@number div 10)"> <br/> </xsl:if> | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
