Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2009, 03:29 PM
udo udo is offline
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default problems with turning data into a reportlike output

I would like to obtain the following output with a variable number ( up to max. n-1 ) of nested xsl:for-each-group, by calling a recursive function.
But I can't get for-each-group work in a way that I can print the grouper once and for the next rows
only emtpy cells until a new group starts.
And how would I position the tablerow tags best?

thanks in advance,
udo

wanted output:
Code:
<table>
<tablerow> <cell>aaa</cell><cell>name2aaa</cell><cell>value1</cell> </tablerow>
<tablerow> <cell>   </cell><cell>        </cell><cell>value1</cell> </tablerow>
<tablerow> <cell>   </cell><cell>        </cell><cell>value2</cell> </tablerow>
<tablerow> <cell>   </cell><cell>name2bbb</cell><cell>value2</cell> </tablerow>
<tablerow> <cell>   </cell><cell>        </cell><cell>value4</cell> </tablerow>
<tablerow> <cell>bbb</cell><cell>name2aaa</cell><cell>value4</cell> </tablerow>
<tablerow> <cell>   </cell><cell>        </cell><cell>value6</cell> </tablerow>
</table>
input:
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
  <row>
    <name1> aaa </name1>
    <name2> name2aaa </name2>
    <name3> value1 </name3>
    <name-n> ... </name-n>
  </row>
  <row>
    <name1> aaa </name1>
    <name2> name2aaa </name2>
    <name3> value1 </name3>
    <name-n> ... </name-n>
  </row>
  <row>
    <name1> aaa </name1>
    <name2> name2bbb </name2>
    <name3> value2 </name3>
    <name-n> ... </name-n>
  </row>
  <row>
    <name1> aaa </name1>
    <name2> name2bbb </name2>
    <name3> value4 </name3>
    <name-n> ... </name-n>
  </row>
  <row>
    <name1> bbb </name1>
    <name2> name2aaa </name2>
    <name3> value4 </name3>
    <name-n> ... </name-n>
  </row>
  <row>
    <name1> bbb </name1>
    <name2> name2aaa </name2>
    <name3> value6 </name3>
    <name-n> ... </name-n>
  </row>
</root>
 
Old February 2nd, 2009, 06:24 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Rather than using grouping for this, because there is a one-to-one correspondence between input rows and output rows, I think it might be easier to use logic of the form:

Code:
<xsl:template match="name1">
  <cell>
     <xsl:value-of select="
        if(. eq ../preceding-sibling::row[1]/name1)
        then ''
        else ."/>
  </cell>
</xsl:template>

<xsl:template match="name2">
  <cell>
     <xsl:value-of select="
        if(deep-equal(../(name1, name2), ../preceding-sibling::row[1]/(name1, name2))
        then ''
        else ."/>
  </cell>
</xsl:template>
That's for rows with fixed column names. But I think you can generalize it to:

Code:
<xsl:template match="row/*">
  <xsl:variable name="col" select="1+count(preceding-sibling::*)"/>
   <cell>
      <xsl:value-of select="
         if(deep-equal(../*[position() le $col], ../preceding-sibling::row[1]/*[position() le $col]))
         then ''
         else ."/>
   </cell>
 </xsl:template>
Not tested.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
udo (February 2nd, 2009)
 
Old February 2nd, 2009, 10:47 AM
udo udo is offline
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Many Thanks, things are becoming clearer now.

But there are two things left:
1) Is deep-equal necessary? The only thing I can think off: If the first group changes, this way you force a redisplay of the second one. Is that correct?

2) I've got another problem now :/ I don't need to group by every column, but only some, in a flexible way; eg I have a variable like:
<xsl:variable name="group" select="'name2', 'name1'"/>
Now I would need to display the columns grouped by name2 and name1 and __sorted__ this way, eg name2 would need to appear left of name1 in the ouput. Is it possible to achieve this, or better reorganize the xml?

Thanks in advance,
udo





Similar Threads
Thread Thread Starter Forum Replies Last Post
data output kciwzehc Access 5 November 28th, 2007 01:10 PM
text output problems dextermagnific XSLT 1 August 10th, 2006 12:31 PM
UTF Output Problems Morrislgn XSLT 1 June 1st, 2005 09:05 PM
About output data to excel momowu0701 Beginning VB 6 0 March 1st, 2005 09:31 AM
problems with stored proc and output parameters zieg42 VB.NET 2002/2003 Basics 1 June 12th, 2004 07:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.