Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xml-dev] Data into 3 even columns

From: "Jesse Mandel" <jesse.mandel@-----.--->
To: xml-dev@-----.---.---
Date: 4/5/2007 6:41:00 PM
Thanks, but I figured it out.

In case people are interested...what I meant was this: 

In my example I have 12 items (both make and model nodes) and so three columns should be 4 each. I don' t want to break up a make node though so the actually output groups them into columns of 5, 4 and 3. Having 4 items in each column would cause the "accord" to in a different column then the rest of the hondas. Same with the tundra/toyotas. Is that more clear?


The solution I came up with is the following snippit. I am new to XML and XSLT so if anyone sees any potential problems or knows a better way (maybe without iterating through all the cars three times...) with this please let me know. It seems to work well though for me.


-Jesse

<xsl:variable name="total" select="count(./make) + count(./make/model)"/>
        <div style="float: left; width:33%;">
          <ul>
            <xsl:for-each select="./make">

              <xsl:if test="count(preceding-sibling::*)+count(preceding-sibling::*/model) &lt; ($total div 3)">
                <li class="make">
                  <xsl:value-of select="@name" />

                </li>
                <xsl:for-each select="./model">
                  <li class="model">
                    <xsl:value-of select="." />

                  </li>
                </xsl:for-each>
              </xsl:if>
            </xsl:for-each>
          </ul>
        </div>
        <div style="float: left; width:33%;">

          <ul>
            <xsl:for-each select="./make">
              <xsl:if test="(count(preceding-sibling::*)+count(preceding-sibling::*/model) > ($total div 3)) and (count(preceding-sibling::*)+count(preceding-sibling::*/model) &lt; ($total div 3)*2)">

                <li class="make">
                  <xsl:value-of select="@name" />
                </li>
                <xsl:for-each select="./model">

                  <li class="model">
                    <xsl:value-of select="." />
                  </li>
                </xsl:for-each>
              </xsl:if>

            </xsl:for-each>
          </ul>
        </div>
        <div style="float: left; width:33%;">
          <ul>
            <xsl:for-each select="./make">

              <xsl:if test="count(preceding-sibling::*)+count(preceding-sibling::*/model) > ($total div 3)*2">
                <li class="make">
                  <xsl:value-of select="@name" />

                </li>
                <xsl:for-each select="./model">
                  <li class="model">
                    <xsl:value-of select="." />

                  </li>
                </xsl:for-each>
              </xsl:if>
            </xsl:for-each>
          </ul>
        </div>



On 4/5/07, Nathan Young -X (natyoung - Artizen at Cisco) <natyoung@c...> wrote:
Hi.

When you say "Ideally it wouldn't break the makes up" what does that
mean?  I had to code a template where it would break a listing on
headers when the headers were within 5 list items of the midpoint, but

if the header was further than that from the midpoint then it would
break at the midpoint and add a continuation header to the top of the
second column.

I actually ended up doing the logic to find the break point in several

steps before starting the output run, then spitting out the column break
using d-o-e when I encountered the break point, although I know that
idea will make XSL idealists shudder.

I think in order to give a good answer one would need to know more about

your column breaking rules.

------------>Nathan

> I have an XML file with make and model car data (example at
> the end). It has an unknown number of makes and an unknown
> number of models per make. I want to use an XSLT doc to

> format it into 3 even columns. Ideally it wouldn't break the
> makes up but it counts both makes and models in the total
> count. See the desired output below.
>
> I am new to XML and have gotten the output to work except

> this part. I can get the count but I don't know how to break
> the data up evenly. Any ideas? Is it possible?
>
> <data>
>
> <make name="ford">
>
> <model>mustang</model>

>
> </make>
> <make name="honda">
>
> <model>civic</model>
> <model>accord</model>
>
> </make>
>
> <make name="toyota">

>
> <model>corolla</model>
> <model>rav4</model>
> <model>tundra</model>
>
> </make>
> <make name="hummer">
>
> <model>h1</model>

> <model>h2</model>
>
> </make>
> </data>
>
> ----------> to ----------->
>
> <div style="float: left">
> <ul>

> <li class="make">ford</li>
> <li class="model">mustang</li>
> <li class="make">honda</li>
> <li class="model">civic</li>

> <li class="model">accord</li>
> </ul>
> </div>
> <div style="float: left">
> <ul>
> <li class="make">toyota</li>

> <li class="model">corolla</li>
> <li class="model">rav4</li>
> <li class="model">tundra</li>
> </ul>
> </div>

> <div style="float: left">
> <ul>
> <li class="make">hummer</li>
> <li class="model">h1</li>
> <li class="model">h2</li>

> </ul>
> </div>
>
> --
> ____________________________
> jessem@c...
> B.S. Computer Science
> University of California Santa Barbara

>


-- 
____________________________
jessem@c...
B.S. Computer Science
University of California Santa Barbara


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent