I am trying to implement a grouping using xslt on xml elements for attributes that do not really share any common value and i am not sure if i should use the muenchian grouping or not, although i already grouped my elements with this method in my code. I also searched in the forum but without luck since most groupings appear to happen on attributes with common values.
More specifically what i am trying to achieve is to print on a pdf, one line for more than one Records that have specific Ids for Att elements with value "PC" on attribute Ty (Att ty="PC"). All this should happen along with my already existing grouping.
Sample of my xml code:
<Document>
<RecordDetails>
<Record>
<contact id="0001" title="Mr" forename="John" surname="Smith" ST='M'/>
<AggSet>
<Att Ty="Addr" Id="43 Menelaou Street" />
<Att Ty="PC" Id="15230" />
<Att Ty="Num" Id="2580052635" />
</AggSet>
<Charge Amount="3.000" PT="P" />
</Record>
<Record>
<contact id="0001" title="Mr" forename="John" surname="Smith" ST='M'/>
<AggSet>
<Att Ty="Addr" Id="65 Dankan Street" />
<Att Ty="PC" Id="15236" />
<Att Ty="Num" Id="2580052635" />
</AggSet>
<Charge Amount="10.000" PT="P" />
</Record>
<Record>
<contact id="0002" title="Dr" forename= "Amy" surname="Jones" ST='Y'/>
<AggSet>
<Att Ty="Addr" Id="28 Karman Street" />
<Att Ty="PC" Id="15237" />
<Att Ty="Num" Id="2584552635" />
</AggSet>
<Charge Amount="-2.000" PT="P" />
</Record>
<Record>
...
</Record>
</RecordDetails>
</Document>
So for instance for records 2,3 I would like to print only 1 line due to the fact that their post codes belong to the same area for me since Ty="PC" means post and I am trying to group on a greater area basis.
I am using the follow xsl on Apache FOP:
<xsl:key name="ct" match="Record[Charge/@PT='P']" use="@ST"/>
<xsl:template match ="RecordDetails">
<xsl:for-each select="Record[generate-id(.)=generate-id(key('ct',@ST)[1])]">
<xsl:if test="@ST='M' and (./AggSet/Att[@Ty='PC']/@Id='15236' or ./AggSet/Att[@Ty='TZ']/@Id='15237' or ... ) ">
<fo:table-row>
<xsl:apply-templates select="."/>
</fo:table-row>
</xsl:if>
<xsl:for-each select="key('ct',@ST)">
<xsl:choose>
<xsl:when test="@ST='M' and (./AggSet/Att[@Ty='PC']/@Id='15236' or ./AggSet/Att[@Ty='TZ']/@Id='15237' or ... ) ">
</xsl:when>
<xsl:otherwise>
<fo:table-row>
<xsl:apply-templates select="."/>
</fo:table-row>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template match="Record">
<fo:table-cell>
<xsl:choose>
<xsl:when test="@ST='M' and (./AggSet/Att[@Ty='PC']/@Id='15236' or ./AggSet/Att[@Ty='TZ']/@Id='15237' or ... )">
<fo:block text-align="center">
<xsl:text>Greater area</xsl:text>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block text-align="center">
<xsl:value-of select="./AggSet/Att[@Ty='PC']/@Id" />
</fo:block>
</xsl:otherwise>
</xsl:choose>
</fo:table-cell>
<fo:table-cell>
<xsl:choose>
<xsl:when test="@ST='M' and (./AggSet/Att[@Ty='PC']/@Id='15236' or ./AggSet/Att[@Ty='TZ']/@Id='15237' or ... )">
<fo:block text-align="center">
<xsl:value-of select="sum(//Record[@ST='M' and (./AggSet/Att[@Ty='PC']/@Id='15236' or ./AggSet/Att[@Ty='TZ']/@Id='15237' or ... )]/contact/Charge/@Amount)" />
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block text-align="center">
<xsl:value-of select="./Charge/@Amount" />
</fo:block>
</xsl:otherwise>
</xsl:choose>
</fo:table-cell>
</xsl:template>
Although i have implemented this logic in the past for elements that actually share a common attribute value within my existing grouping, the above code gives me no lines at all for my wanting aggregation and i am wondering if there's something wrong with my OR conditions and for some reason it becomes false.
Am I missing something ? Any help would be much appreciated,
Thanks
Edit: As Tomalak points out in my case what I am trying to do is to implement manual groups, meaning indeed hardcoded conditions inside the code. There is no generic way to calculate these values for me now.