XSLT Grouping Help
Hi,
I am trying to group a collection of nodes using XSLT 1.0. I almost have the solution, but I get a duplicate of the SERVICE_INSTANCE_DESC in the output. I am trying to group on the SERVICE_INSTANCE_DESC node. I also need to filter on the SERVICE_LOCATION_ID, as the ACCOUNT_ID can have multiple SERVICE_LOCATION_ID's and the output is displayed based on a href passing the SERVICE_LOCATION_ID into the street_name parameter.
XSLT:-
<xsl:key name="account" match="row" use="SERVICE_INSTANCE_DESC"/>
<xsl:template match="data_results">
<xsl:for-each select="row[count(. | key('account', SERVICE_INSTANCE_DESC)[1]) = 1]">
<xsl:sort select="SERVICE_INSTANCE_DESC" />
<xsl:for-each select="key('account',SERVICE_INSTANCE_DESC)">
<xsl:if test ="SERVICE_LOCATION_ID = $street_name">
<xsl:variable name="first_instance" select="SERVICE_INSTANCE_DESC[1]" />
<b><xsl:value-of select="$first_instance" /></b><br />
</xsl:if>
</xsl:for-each>
<xsl:for-each select="key('account', SERVICE_INSTANCE_DESC)">
<xsl:sort select="MODEL_NAME" />
<xsl:if test ="SERVICE_LOCATION_ID = $street_name">
<xsl:value-of select="SERVICE_LOCATION_ID" /><br />
<xsl:value-of select="MODEL_NAME" /><br /><br />
</xsl:if>
</xsl:for-each>
</xsl:for-each>
XML:-
<data_results>
<row>
<ACCOUNT_ID>9999999</ACCOUNT_ID>
<SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
<SERVICE_INSTANCE_DESC>OUTLET</SERVICE_INSTANCE_DESC>
<MODEL_NAME>Atlas Satellite Set Top</MODEL_NAME>
</row>
<row>
<ACCOUNT_ID>9999999</ACCOUNT_ID>
<SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
<SERVICE_INSTANCE_DESC>OUTLET</SERVICE_INSTANCE_DESC>
<MODEL_NAME>Irdeto Delta V4</MODEL_NAME>
</row>
<row>
<ACCOUNT_ID>9999999</ACCOUNT_ID>
<SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
<SERVICE_INSTANCE_DESC>Family Room</SERVICE_INSTANCE_DESC>
<MODEL_NAME>Titan Set Top</MODEL_NAME>
</row>
<row>
<ACCOUNT_ID>9999999</ACCOUNT_ID>
<SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
<SERVICE_INSTANCE_DESC>Family Room</SERVICE_INSTANCE_DESC>
<MODEL_NAME>Irdeto Delta V4</MODEL_NAME>
</row>
<row>
<ACCOUNT_ID>9999999</ACCOUNT_ID>
<SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
<SERVICE_INSTANCE_DESC>Bedroom</SERVICE_INSTANCE_DESC>
<MODEL_NAME>Titan Set Top</MODEL_NAME>
</row>
<row>
<ACCOUNT_ID>9999999</ACCOUNT_ID>
<SERVICE_LOCATION_ID>111111</SERVICE_LOCATION_ID>
<SERVICE_INSTANCE_DESC>Bedroom</SERVICE_INSTANCE_DESC>
<MODEL_NAME>Irdeto Delta V4</MODEL_NAME>
</row>
<row>
<ACCOUNT_ID>9999999</ACCOUNT_ID>
<SERVICE_LOCATION_ID>222222</SERVICE_LOCATION_ID>
<SERVICE_INSTANCE_DESC>Family Room</SERVICE_INSTANCE_DESC>
<MODEL_NAME>Irdeto Delta V4</MODEL_NAME>
</row>
</data_results>
Output:-
Bedroom
Bedroom
111111
Irdeto Delta V4
111111
Titan Set Top
Family Room
Family Room
111111
Irdeto Delta V4
111111
Titan Set Top
OUTLET
OUTLET
111111
Atlas Satellite Set Top
111111
Irdeto Delta V4
Desired Output:-
Bedroom
111111
Irdeto Delta V4
111111
Titan Set Top
Family Room
111111
Irdeto Delta V4
111111
Titan Set Top
OUTLET
111111
Atlas Satellite Set Top
111111
Irdeto Delta V4
I tried using
<xsl:template match = "/data_results" >
<xsl:apply-templates select ="row[(SERVICE_LOCATION_ID = $street_name)]" />
</xsl:template>
but had problems with the count in the <xsl:for-each select="row[count(. | key('account', SERVICE_INSTANCE_DESC)[1]) = 1]">
I am new to keys and grouping, so any help is appreciated.
Thanks
|