|
Subject: Re: [xsl] Controlling tabular layout of a nodeset From: Mukul Gandhi <mukulw3@xxxxxxxxx> Date: Fri, 25 Jul 2003 11:29:27 -0700 (PDT) |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Controlling tabular layou, Wendell Piez | Thread | [xsl] XPATH to be used in a for-ea, Rahul Patwardhan |
| Re: [xsl] XHTML to PDF, Wendell Piez | Date | [xsl] How to keep DOCTYPE declarati, Taro Ikai |
| Month |