[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Controlling tabular layout of a nodeset

Subject: Re: Controlling tabular layout of a nodeset
From: Mukul Gandhi <mukulw3@xxxxxxxxx>
Date: Fri, 25 Jul 2003 11:29:27 -0700 (PDT)
prvalue
Hi John,
  i have assumed the following XML. Hope your XML is
similar to this.

<?xml version="1.0" encoding="UTF-8"?>
<recordset>
  <record>
    <property>property2</property>
    <prvalue>prvalue2</prvalue>
    <user_id>user_id4</user_id>
    <acct_id>acct_id6</acct_id>
  </record>
  <record>
    <property>property1</property>
    <prvalue>prvalue1</prvalue>
    <user_id>user_id1</user_id>
    <acct_id>acct_id1</acct_id>
  </record>
  <record>
    <property>property2</property>
    <prvalue>prvalue2</prvalue>
    <user_id>user_id3</user_id>
    <acct_id>acct_id3</acct_id>
  </record>
  <record>
    <property>property1</property>
    <prvalue>prvalue1</prvalue>
    <user_id>user_id1</user_id>
    <acct_id>acct_id2</acct_id>
  </record>
  <record>
    <property>property2</property>
    <prvalue>prvalue2</prvalue>
    <user_id>user_id4</user_id>
    <acct_id>acct_id5</acct_id>
  </record>
  <record>
    <property>property1</property>
    <prvalue>prvalue1</prvalue>
    <user_id>user_id2</user_id>
    <acct_id>acct_id1</acct_id>
  </record>
  <record>
    <property>property2</property>
    <prvalue>prvalue2</prvalue>
    <user_id>user_id3</user_id>
    <acct_id>acct_id4</acct_id>
  </record>
</recordset>

The complete XSL is
-------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
 <xsl:key name="x" match="recordset/record"
use="property"/>
 <xsl:key name="y" match="recordset/record"
use="concat(property,':',user_id)"/>

 <xsl:template match="recordset">
   <html>
     <head>
	<title>Grouping</title>
     </head>
     <body>
       <table border="1">
	<xsl:apply-templates select="record"/>
       </table>
     </body>
   </html>
 </xsl:template>
 
 <xsl:template match="record">
   <xsl:if test="generate-id(.) =
generate-id(key('x',property)[1])">
   <xsl:for-each select="key('x',property)">
     <xsl:if test="position() = 1">
       <tr>
	<td>
  	 <xsl:value-of select="property"/>
 	</td>
	<td>
	- <xsl:value-of select="prvalue"/>
	</td>
      </tr>
    </xsl:if>
    <xsl:if test="generate-id(.)=generate-id(key('y',
concat(property,':',user_id))[1])">
      <xsl:for-each
select="key('y',concat(property,':',user_id))">
        <xsl:if test="position() = 1">
	<tr>
	 <td>
	  <xsl:value-of select="user_id"/>
	 </td>
	 <td>
	   <xsl:for-each select="key('y',
concat(property,':',user_id))">				   <xsl:value-of
select="acct_id"/>
	<xsl:if test="position()!=last()">,</xsl:if>
	</xsl:for-each>
	</td>
    </tr>				
  </xsl:if>
  </xsl:for-each>
 </xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

We need to use composite keys as suggested by
J.Pietschmann. 

Hope the above XSL would solve your problem.

Regards,
Mukul


--- John Marshall <John.Marshall@xxxxxxxxxxxxxx>
wrote:
> I am using Xalan-j_2_5_1. I have a set of elements
> (recovered by SQL), each containing four child
> elements: property, prvalue, user_id and acct_id. I
> can use the Muench method to obtain a nodeset
> containing all elements with a particular value of
> "property". I can sort this into the required order.
> Using a for-each loop I can display this in a table
> as:
> 
> +---------+--------+--------+--------+
> |property1|prvalue1|user_id1|acct_id1|
> +---------+--------+--------+--------+
> |property1|prvalue1|user_id1|acct_id2|
> +---------+--------+--------+--------+
> |property1|prvalue1|user_id2|acct_id1|
> +---------+--------+--------+--------+
> 
> I want to display it as:
> +--------+------------------+
> |property1 - prvalue1       |
> +--------+------------------+
> |user_id1|acct_id1, acct_id2|
> +--------+------------------+
> |user_id2|acct_id1 ...      |
> +--------+------------------+
> 
> In order to do this I need to either access the
> element in my nodeset before "." or store the values
> of prvalue and user_id from one iteration to access
> in the next iteration, to do the appropriate format
> control.
> 
> I can get the result I need by successively
> searching the source tree, but the length of this
> table makes this unacceptably slow (4 1/2 hours).
> 
> I had hoped that EXSLT set:leading() would provide a
> solution, but I note that the documentation shows
> this returns a node set in document order, not in
> the order of the sorted subset I have obtained, so I
> have not pursued this.
> 
> This seems such a common requirement that I am sure
> there is a straightforward answer and I apologise if
> I have missed it.
> 
> Thank you.
> 
> John Marshall
> Accurate Software
> 
> 80 Peach Street, Wokingham, Berkshire, RG40 1XH, UK.
> Tel: +44 (0)118 977 3889
> Fax: +44 (0)118 977 1260
> http://www.accuratesoftware.com 
> 
> 
> Accurate Software
> 
> info@xxxxxxxxxxxxxxxxxxxx
> www.accuratesoftware.com
> 
> Europe . North America . Australasia . Africa
> 
> The information in this email is confidential and
> privileged and is intended only for the use of the
> individual or entity listed above.  If you are
> neither the intended individual, or entity listed
> above, nor the person responsible for the delivery
> of this email to the intended recipients, you are
> hereby notified that any unauthorised distribution,
> copying or use of this email is prohibited. If you
> have received this email in error, please notify the
> Accurate system manager at
> postmaster@xxxxxxxxxxxxxxxxxxxx or on +44 (0)118 977
> 3889.  The views expressed in this communication may
> not necessarily be the views held by the Accurate
> Group.
> 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.