I want to better understand XSLT 1.0 nested grouping using Muenchian grouping



I have XML data and would like to group it by INSPTR and ELVINSP_DT. Questions at the end of the post.


Here is my XML:



<AS400_ELVPINS00Collection>
<ObjList>
<AS400_ELVPINS00>
<ID>123456</ID>
<ELVINSP_DT>2014-05-01</ELVINSP_DT>
<DetailData>Out Sick</DetailData>
<INSPTR>
<ID>555123</ID>
<INSPTR_NAME>Doe, John P</INSPTR_NAME>
<MoreDetailData>Northeast Region</MoreDetailData>
</INSPTR>
</AS400_ELVPINS00>
<AS400_ELVPINS00>
<ID>123459</ID>
<ELVINSP_DT>2014-05-02</ELVINSP_DT>
<DetailData>Nobody showed up</DetailData>
<INSPTR>
<ID>555123</ID>
<INSPTR_NAME>Doe, John P</INSPTR_NAME>
<MoreDetailData>Northeast Region</MoreDetailData>
</INSPTR>
</AS400_ELVPINS00>
<AS400_ELVPINS00>
<ID>123463</ID>
<ELVINSP_DT>2014-05-01</ELVINSP_DT>
<DetailData>Job Location was clear</DetailData>
<INSPTR>
<ID>555124</ID>
<INSPTR_NAME>Smith, John T</INSPTR_NAME>
<MoreDetailData>South Central Region</MoreDetailData>
</INSPTR>
</AS400_ELVPINS00>
</ObjList>
</AS400_ELVPINS00Collection>


I'd like the data listed like this:



Doe, John P
2014-05-01 - Out Sick
2014-05-02 - Nobody showed up
Smith, John T
2014-05-01 - Job Location was clear


Here is what I'm trying for XSLT:



<xsl:key name="keyInsptr" match="ObjList/AS400_ELVPINS00" use="INSPTR" />
<xsl:key name="keyDate" match="ObjList/AS400_ELVPINS00" use="ELVINSP_DT" />

<fo:flow flow-name="xsl-region-body">
<xsl:for-each select="ObjList/AS400_ELVPINS00[generate-id(.)=generate-id(key('keyInsptr',INSPTR)[1])]">
<xsl:sort select="INSPTR/INSPTR_NAME"/>

<!-- This part works -->
<fo:block>
<xsl:value-of select="INSPTR/INSPTR_NAME" />
</fo:block>

<!-- This part DOES NOT work -->
<xsl:variable name="vrInsptID">
<xsl:value-of select="INSPTR/INSPTR_NAME"/>
</xsl:variable>
<xsl:variable name="lstInsp" select="ObjList/AS400_ELVPINS00[INSPTR/INSPTR_NAME=vrInsptrID]" />
<xsl:for-each select="lstInsp[generate-id(.)=generate-id(key('keyDate',ELVINSP_DT)[1])]">
<fo:block>
<xsl:text> - </xsl:text>
<xsl:call-template name="dateFormat">
<xsl:with-param name="value" select="lstInsp/ELVINSP_DT" />
</xsl:call-template>
</fo:block>
</xsl:for-each>


</xsl:for-each>
</fo:flow>


I understand that generate-id creates a unique 'id' at runtime for an element, so I am assuming that generate-id(.) will generate an id for each ObjList/AS400_ELVPINS00 element to use in the match, correct?


What is generate-id(key('keyInsptr',INSPTR)[1]) doing? What kind of results does that make? I'm trying to visualize this.


When I do the 'for-each' on keyInsptr, what Node-set am I working with inside that for-each?


How do I get the inner 'for-each' to cycle through the dates correctly?


I am not just looking to get this working, but to also understand how it should work. Thank you.


No comments:

Post a Comment