Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

OT - Dynamic data into columns in XSLT

by rashley (Scribe)
on Dec 20, 2005 at 15:47 UTC ( [id://518095]=perlquestion: print w/replies, xml ) Need Help??

rashley has asked for the wisdom of the Perl Monks concerning the following question:

Yes, I know that this is off-topic, but I haven't been able to find info on this anywhere else, so I go to what I consider the most reliable knowledge source I know... PM.

I'm fairly new to XSLT and have a problem.

I have a page that includes the following nodes:

<xsl:template name="deptIndex"> <xsl:variable name="colCount" select="3"/> <xsl:element name="p"> Department Index </xsl:element> <xsl:element name="table"> <xsl:for-each select="pcr_report/info/department[position() mod $c +olCount = 1]"> <xsl:element name="tr"> <xsl:apply-templates select=". | following-sibling::pcr_report +/info/department[position() &lt; $colCount]" mode="deptIndexTD"/> </xsl:element> </xsl:for-each> </xsl:element> </xsl:template> <xsl:template match="department" mode="deptIndexTD"> <xsl:element name="td"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="concat('#', .)"/> </xsl:attribute> <xsl:value-of select="."/> </xsl:element> </xsl:element> </xsl:template>
These nodes display an index of departments at the top of a larger page.

Currently they display simply as a very long vertical list.

I need them to display in 5 columns like this:

Dept1 Dept5 Dept9 Dept13 Dept17 Dept2 Dept6 Dept10 Dept14 Dept18 Dept3 Dept7 Dept11 Dept15 Dept19 Dept4 Dept8 Dept12 Dept16 Dept20
I've googled 'till I just can't google no more, and I've come up wish zilch.

Anyone know how to do this?

Replies are listed 'Best First'.
Re: OT - Dynamic data into columns in XSLT
by simon.proctor (Vicar) on Dec 20, 2005 at 16:09 UTC
    The way I did this at work was to first figure out how many items I was dealing with and then work out the correct partitions for my list. I then did a series of foreaches using pos, one for each column.

    However, I achieved the columnar effect using a style sheet and divs.

    This freed me up from trying to fill a table (which you are doing) as I could fill my data vertically whereas a table requires me to fill horizontally. This is a bit different (possibly harder!) to complete.

    So .... I filled a set of divs with my partitioned data and then used CSS to move them where I wanted. This is easy enough using the old 'float' syntax.

    I can't provide any more help now as I am at work. If you need more assistance put your XML and your expected output on your scratchpad or as a reply to this node. I am sure someone else can help . . . I'd be interested in seeing their answer too.
Re: OT - Dynamic data into columns in XSLT
by idsfa (Vicar) on Dec 20, 2005 at 17:04 UTC

    You might be interested in this article on using CSS to turn a single column list into multiple columns. You may find that this problem is much easier if you separate the content (XML/XHTML) from the presentation.


    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
Re: OT - Dynamic data into columns in XSLT
by planetscape (Chancellor) on Dec 20, 2005 at 22:39 UTC
      I need help to display one field US State Name stored as title column from a US State List in 3 columns that snake. For example, if there are 60 rows of data, I want items 1-15 to show up in column 1 and items 16 - 29 in column 2 and so on... here is my data view webpart xsl : can some help me to find out how to display it in 3 columns?
      <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="ht +tp://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-resu +lt-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.c +om/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft. +com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebPart +s/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transfo +rm" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Mi +crosoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" +> <xsl:output method="html" indent="no"/> <xsl:decimal-format NaN=""/> <xsl:param name="dvt_apos">'</xsl:param> <xsl:variable name="dvt_1_automode">0</xsl:variable> <xsl:template match="/"> <xsl:call-template name="dvt_1"/> </xsl:template> <xsl:template name="dvt_1"> <xsl:variable name="dvt_StyleName">2ColCma</xsl:variable> <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" /> <table border="0" width="100%"> <tr> <xsl:call-template name="dvt_1.body"> <xsl:with-param name="Rows" select="$Rows" /> </xsl:call-template> </tr> </table> </xsl:template> <xsl:template name="dvt_1.body"> <xsl:param name="Rows" /> <xsl:for-each select="$Rows"> <xsl:call-template name="dvt_1.rowview" /> </xsl:for-each> </xsl:template> <xsl:template name="dvt_1.rowview"> <td valign="top" width="50%" class="ms-vb"> <b> <xsl:value-of select="@Title" /> </b> <br /> <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1"> <br /><span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDe +lims(string(@ID))" ddwrt:ammode="view" /> </xsl:if> </td> <xsl:if test="position() mod 2 = 0" ddwrt:cf_ignore="1"> <xsl:text disable-output-escaping="yes">&lt;/tr&gt;</xsl:text +> <xsl:if test="position() != last()" ddwrt:cf_ignore="1"> <xsl:text disable-output-escaping="yes">&lt;tr&gt;</xsl:t +ext> </xsl:if> </xsl:if> </xsl:template> </xsl:stylesheet>
      Thanks in Advance
Re: OT - Dynamic data into columns in XSLT
by Anonymous Monk on Dec 20, 2005 at 20:52 UTC
    Something like this:
    <xsl:variable name="cols" select="5"/> <xsl:variable name="rows" select="ceiling(last() / $cols)"/> <xsl:for-each select="yourTag[position() &lt;= $rows"> <tr> <!-- self::position() below refers to the value of position() HERE + --> <xsl:for-each select="yourTag[position() mod $rows = self::positio +n()]"> <td><xsl:value-of select="..."/></td> </xsl:for-each> </tr> </xsl:for-each>

      Actually, that would only work as current()/position(), since the self:: axis refers to the predicate context.

      Whatever. Just stick the position() in an xsl:variable and call it good enough.

      I came up with something very similar to this as well.

      Unfortunately, it turns out that there's something wrong with our system that's causing the

      Element[n]
      syntax to evaluate incorrectly.

      As long as that's the case, this can't be solved.

      Still, thanks for the input.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://518095]
Approved by monkfan
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2024-03-28 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found