RE: [xsl] Is this about grouping ?

Subject: RE: [xsl] Is this about grouping ?
From: Benoit_Aumars@xxxxxxxxxxxx
Date: Mon, 2 Jul 2001 12:22:11 +0100
Mike, Trevor,

Thanks for your reply.
Obviously I did not clearly explained my problem.

Let's start again.
This is my original source ( with the correct indentation ) :
<?xml version="1.0"?>
<topic>
	<a>ItemA</a>
	<b>ItemB</b>
	<f>text1</f>
	<g>text2</g>
	<h>text3</h>
	<i>text4</i>

	<a>ItemA</a>
	<b>ItemB</b>
	<f>text5</f>
	<g>text6</g>
	<h>text7</h>
	<i>text8</i>

	<a>ItemA</a>
	<b>ItemB</b>
	<f>text9</f>
	<g>text10</g>
	<h>text11</h>
	<i>text12</i>
</topic>

and the result that I want to have  ( with the correct indentation ) :
<?xml version="1.0"?>
<topic>
	<a>ItemA</a>
	<b>ItemB</b>
		<f>text1</f>
		<g>text2</g>
		<h>text3</h>
		<i>text4</i>
		<f>text5</f>
		<g>text6</g>
		<h>text7</h>
		<i>text8</i>
		<f>text9</f>
		<g>text10</g>
		<h>text11</h>
		<i>text12</i>
</topic>

So, I need to group by <a> and <b>. Those elements are constant in the
source document.
I will ignore the sort order because the original source is already sorted.
If my XSL script is like this :

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no" />

<xsl:key name="group" match="f | g | h | i" use="//a" />

<xsl:template match="topic">
<topic>
	<a>
		<xsl:value-of select="//a[1]"/>
	</a>
	<b>
		<xsl:value-of select="//b[1]"/>
	</b>

	<!--
    <xsl:for-each select="key('group' ,a)">
		<xsl:choose>
			<xsl:when test="//f">
				<xsl:text/>    <xsl:value-of
select="."/><xsl:text/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text/>    <xsl:value-of
select="."/><xsl:text/>
			</xsl:otherwise>
		</xsl:choose>
    </xsl:for-each>
	-->

    <xsl:copy-of select="key('group' ,a)"/>

</topic>
</xsl:template>

</xsl:transform>

the result will be :
<?xml version="1.0" encoding="UTF-8"?>
<topic>
<a>ItemA</a>
<b>ItemB</b>
<f>text1</f>
<g>text2</g>
<h>text3</h>
<i>text4</i>
<f>text5</f>
<g>text6</g>
<h>text7</h>
<i>text8</i>
<f>text9</f>
<g>text10</g>
<h>text11</h>
<i>text12</i>
</topic>

The problem with that XSL using <xsl:copy-of> is that I can't control over
the indentation
from <f> to <i>. So I have to use the <xsl:for-each>.
With <xsl:for-each>, I can control over the node-set returned by key(), i.e
concatenate <f> and <g>.
The above <xsl:for-each> is uncomplete or wrong completely.

What I would like you to help me is how can I use <xsl:for-each> :
1. to have a proper indentation from <f> to <i> ?
2. to concatenate 2 elements ,i.e <f> and <g> into <new>, so the final
result is :
<?xml version="1.0" encoding="UTF-8"?>
<topic>
    <a>ItemA</a>
    <b>ItemB</b>
        <new>text1+text2</new>
        <h>text3</h>
        <i>text4</i>
        <new>text5+text6</new>
        <h>text7</h>
        <i>text8</i>
        <new>text9+text10</new>
        <h>text11</h>
        <i>text12</i>
</topic>

I would appreciate any help.

Thanks
Benoit Aumars.


************************************************************
JLT Management Services Limited
6 Crutched Friars, London EC3N 2PH. Co Reg No 1536540
Tel: (44) (0)20 7528 4000   Fax: (44) (0)20 7528 4500
http://www.jltgroup.com
------------------------------------------------------------
The content of this e-mail (including any attachments) as 
received may not be the same as sent. If you consider that 
the content is material to the formation or performance of 
a contract or you are otherwise relying upon its accuracy, 
you should consider requesting a copy be sent by facsimile 
or normal mail.  The information in this e-mail is 
confidential and may be legally privileged. If you are not 
the intended recipient, please notify the sender immediately 
and then delete this e-mail entirely - you must not retain, 
copy, distribute or use this e-mail for any purpose or 
disclose any of its content to others.

Opinions, conclusions and other information in this e-mail 
that do not relate to the official business of JLT 
Management Services Limited shall be understood as neither 
given nor endorsed by it.  Please note we intercept and 
monitor incoming / outgoing e-mail and therefore you should 
neither expect nor intend any e-mail to be private in nature.

We have checked this e-mail for viruses and other harmful 
components and believe but not guarantee it virus-free prior 
to leaving our computer system.  However, you should satisfy 
yourself that it is free from harmful components, as we do 
not accept responsibility for any loss or damage it may 
cause to your computer systems.
************************************************************

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


Current Thread