Agrupamento xsl de nós repetitivos por elemento xml em xslt1
Eu tenho uma estrutura xml complexa que se parece com:
<Items>
<Item>
<ItemTexts>
<ItemText>
<ItemTextsType>type1</ItemTextsType>
<ItemTextsTypeDesc>description11</ItemTextsTypeDesc>
<ItemTextsLine>1</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type1</ItemTextsType>
<ItemTextsTypeDesc>description12</ItemTextsTypeDesc>
<ItemTextsLine>2</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type2</ItemTextsType>
<ItemTextsTypeDesc>description21</ItemTextsTypeDesc>
<ItemTextsLine>3</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type2</ItemTextsType>
<ItemTextsTypeDesc>description22</ItemTextsTypeDesc>
<ItemTextsLine>4</ItemTextsLine>
</ItemText>
</ItemTexts>
</Item>
<Item>
<ItemTexts>
<ItemText>
<ItemTextsType>type1</ItemTextsType>
<ItemTextsTypeDesc>description11</ItemTextsTypeDesc>
<ItemTextsLine>1</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type1</ItemTextsType>
<ItemTextsTypeDesc>description12</ItemTextsTypeDesc>
<ItemTextsLine>2</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type2</ItemTextsType>
<ItemTextsTypeDesc>description21</ItemTextsTypeDesc>
<ItemTextsLine>3</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type2</ItemTextsType>
<ItemTextsTypeDesc>description22</ItemTextsTypeDesc>
<ItemTextsLine>4</ItemTextsLine>
</ItemText>
</ItemTexts>
</Item>
<Item>
<ItemTexts>
<ItemText>
<ItemTextsType>type1</ItemTextsType>
<ItemTextsTypeDesc>description11</ItemTextsTypeDesc>
<ItemTextsLine>1</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type1</ItemTextsType>
<ItemTextsTypeDesc>description12</ItemTextsTypeDesc>
<ItemTextsLine>2</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type2</ItemTextsType>
<ItemTextsTypeDesc>description21</ItemTextsTypeDesc>
<ItemTextsLine>3</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type2</ItemTextsType>
<ItemTextsTypeDesc>description22</ItemTextsTypeDesc>
<ItemTextsLine>4</ItemTextsLine>
</ItemText>
</ItemTexts>
</Item>
<Item>
<ItemTexts>
<ItemText>
<ItemTextsType>type3</ItemTextsType>
<ItemTextsTypeDesc>description31</ItemTextsTypeDesc>
<ItemTextsLine>1</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type3</ItemTextsType>
<ItemTextsTypeDesc>description32</ItemTextsTypeDesc>
<ItemTextsLine>2</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type2</ItemTextsType>
<ItemTextsTypeDesc>description21</ItemTextsTypeDesc>
<ItemTextsLine>3</ItemTextsLine>
</ItemText>
<ItemText>
<ItemTextsType>type2</ItemTextsType>
<ItemTextsTypeDesc>description22</ItemTextsTypeDesc>
<ItemTextsLine>4</ItemTextsLine>
</ItemText>
</ItemTexts>
</Item>
</Items>
Eu corro com xsl em cada item como:
<xsl:for-each select="Items/Item">
Eu preciso de um exemplo de como agrupar<ItemText>
por<ItemTextsType>
individualmente para cada<Item>
então o resultado será como:
Primeiro<Item>
neste exemplo:
tipo 1
description11
description12
tipo 2
description21
description22
Por segundoItem
neste exemplo:
type3
description31
description32
tipo 2
description21
description22
Claro que vou organizar o resultado em uma tabela como:
<table width="100%" border="1" style="display: block;">
<tbody>
<tr>
<td id="SelectedRowLinkageContents">
<table width="100%" dir="ltr">
<tbody>
<tr style="background-color: #507CD1; text-align: center">
<td colspan="3" style="font: bold; color: white">
Item1
</td>
</tr>
<tr>
<td style="height: 35px; font: bold; color: #507CD1;">
type1
</td>
</tr>
<tr>
<td>
desription11
</td>
</tr>
<tr>
<td>
desription12
</td>
</tr>
<tr>
<td style="height: 35px; font: bold; color: #507CD1;">
type2
</td>
</tr>
<tr>
<td>
desription21
</td>
</tr>
<tr>
<td>
desription22
</td>
</tr>
<tr>
<td>
desription23
</td>
</tr>
</tbody>
</table>
<table width="100%" dir="ltr">
<tbody>
<tr style="background-color: #507CD1; text-align: center">
<td colspan="3" style="font: bold; color: white">
Item2
</td>
</tr>
<tr>
<td style="height: 35px; font: bold; color: #507CD1;">
type1
</td>
</tr>
<tr>
<td>
desription11
</td>
</tr>
<tr>
<td>
desription12
</td>
</tr>
<tr>
<td style="height: 35px; font: bold; color: #507CD1;">
type2
</td>
</tr>
<tr>
<td>
desription21
</td>
</tr>
<tr>
<td>
desription23
</td>
</tr>
</tbody>
</table>
<table width="100%" dir="ltr">
<tbody>
<tr style="background-color: #507CD1; text-align: center">
<td colspan="3" style="font: bold; color: white">
Item3
</td>
</tr>
<tr>
<td style="height: 35px; font: bold; color: #507CD1;">
type1
</td>
</tr>
<tr>
<td>
desription11
</td>
</tr>
<tr>
<td>
desription12
</td>
</tr>
<tr>
<td style="height: 35px; font: bold; color: #507CD1;">
type2
</td>
</tr>
<tr>
<td>
desription21
</td>
</tr>
<tr>
<td>
desription23
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
O ponto é que há um agrupamento separado para cada<Item>
em seu próprio<table>
e dentro disso<table>
há agrupando por<ItemTextsType>
Eu tentei algo como
<xsl:key name="item-texts-type" match="ItemText" use="ItemTextsType" />
<xsl:for-each select="ItemTexts/ItemText[count(. | key('item-texts-type', ItemTextsType)[1]) = 1]">
<xsl:sort select="ItemTextsType" />
<tr>
<td style ="height:35px;font: bold; color:#507CD1;">
<xsl:value-of select="ItemTextsType" />
</td>
</tr>
<xsl:for-each select="key('item-texts-type', ItemTextsType)">
<tr>
<td>
<xsl:value-of select="ItemTextsTypeDesc" />
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
mas só funciona emnão nós repetitivos (se houvesse apenas um<Item>
funcionaria bem).Eu não posso mudar xml porque vem do cliente.
Por favor me ajude, eu preciso disso o mais rápido possível.
Obrigado !!!!