Group items with XSLT in DotNetNuke Form and List
I have to group a set of items using Form and List (DotNetNuke Module) and XSLT.
XML:
<UserDefinedTable>
<Data>
<UserDefinedRowId>1</UserDefinedRowId>
<Título>ABC</Título>
<Tipo>Type1</Tipo>
<URL>
<a href="" target="_blank">http://www.example.com/</a>
</URL>
<Imagem>
<img alt="Imagem" title="Imagem" src="/Portals/0/Links/img.png" />
</Imagem>
<Ordem>4</Ordem>
<Created_x0020_by>Example</Created_x0020_by>
<Created_x0020_at>2011-05-04T13:40:15+01:00</Created_x0020_at>
<Changed_x0020_by>Example</Changed_x0020_by>
<Changed_x0020_at>2011-05-10T16:57:56+01:00</Changed_x0020_at>
<EditLink>
http://example.com/page/page/tabid/74/ctl/edit/mid/520/Default.aspx?UserDefinedRowId=1
</EditLink>
<Created_x0020_by_UDT_Original>host</Created_x0020_by_UDT_Original>
<Created_x0020_by_UDT_Caption>Example</Created_x0020_by_UDT_Caption>
<Created_x0020_at_UDT_Value><!--063440113215-->04-05-2011 13:40</Created_x0020_at_UDT_Value>
<Created_x0020_at_UDT_Ticks>634401132150000000</Created_x0020_at_UDT_Ticks>
<Changed_x0020_by_UDT_Original>host</Changed_x0020_by_UDT_Original>
<Changed_x0020_by_UDT_Caption>Example</Changed_x0020_by_UDT_Caption>
<Changed_x0020_at_UDT_Value><!--063440643476-->10-05-2011 16:57</Changed_x0020_at_UDT_Value>
<Changed_x0020_at_UDT_Ticks>634406434760000000</Changed_x0020_at_UDT_Ticks>
<URL_UDT_Url/>
<URL_UDT_Caption>http://www.example.com/</URL_UDT_Caption>
<URL_UDT_Original>http://www.example.com/</URL_UDT_Original>
<Imagem_UDT_Url>/Portals/0/Links/image.png</Imagem_UDT_Url>
<Imagem_UDT_Caption>Imagem</Imagem_UDT_Caption>
<Imagem_UDT_Original>FileID=252</Imagem_UDT_Original>
</Data>
</UserDefinedTable>
The element Data represents an item on list.
I want to group the results by Tipo. I mean:
Type1
Elem1 Elem4 Elem5 ...
Type2
Elem2 Elem3 ...
The XSLT I'm using now doesn't work:
<xsl:text>Type1</xsl:text>
<xsl:template match="udt:Data" mode="list">
<xsl:call-template name="Type1" />
</xsl:template>
<xsl:text>Type2</xsl:text>
<xsl:template match="udt:Data" mode="list">
<xsl:call-template name="Type2" />
</xsl:template>
<xsl:template name="Type1">
<xsl:if test="contains("Type1", udt:Tipo)">开发者_如何学Python
<div style="float:left; margin: 5px;">
<xsl:call-template name="EditLink" />
<a href="{udt:URL_UDT_Original}" target="_blank">
<img src="{udt:Imagem_UDT_Url}" title="{udt:Título}" />
</a>
</div>
</xsl:if>
</xsl:template>
<xsl:template name="Type2">
<xsl:if test="contains("Type2", udt:Tipo)">
<div style="float:left; margin: 5px;">
<xsl:call-template name="EditLink" />
<a href="{udt:URL_UDT_Original}" target="_blank">
<img src="{udt:Imagem_UDT_Url}" title="{udt:Título}" />
</a>
</div>
</xsl:if>
</xsl:template>
Any ideas?
Thanks in advance!
To be honest, I'm not 100% sure what you're end goal is, but here's a simple example that should demonstrate the principles necessary to group elements using the Muenchian method:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="tipo" match="Data" use="Tipo" />
<xsl:template match="Data" />
<xsl:template match="Data[generate-id() = generate-id(key('tipo',Tipo)[1])]" >
<xsl:value-of select="Tipo" />
<xsl:for-each select="key('tipo',Tipo)">
<xsl:value-of select="EditLink" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Swap out the two <xsl:value-of
statements for whatever processing you need on the group/item respectively.
精彩评论