I have a XML document with HISTORY and SCHEDULE elements. I need to iterate through the SCHEDULE elements and build a table row. For that schedule there could be 0 or many history elements that I also need to add to the table but without duplicating!
I'm using a Foreach to iterate through the schedule then a nested foreach to iterate through the history.
The problem is that when I loop through the history I duplicate the entry I added when processing the schedules. I 've tried to check that the not(DOCUMENT_ID=$docid) but it doesnt seem to equate to true.
I cant get not($history/DOCUMENT_ID)=$docid) to evaluate as I would expect. I thought it would mean that if a history item is found to have the document id of the schedule added then dont allow it to be added. Does anyone know what I might be doing wrong or can suggest and alternative please? I'd be very grateful.
I've also tried using a key and generate-id() but I'm not that experienced with them.
Thanks
Matt
Code:
<HISTORY>
<DATE_INSERTED>
<DAY>16</DAY>
<MONTH>02</MONTH>
<YEAR>2006</YEAR>
</DATE_INSERTED>
<DESCRIPTION>Office Copies Received</DESCRIPTION>
<EXTRA_TEXT>>></EXTRA_TEXT>
<TIME_USED/>
<TIME_CHARGE>0.00</TIME_CHARGE>
<TIME_COST>0.00</TIME_COST>
<CASE_HOLDER>Melissa Johnson</CASE_HOLDER>
<USER_ID>melissa</USER_ID>
<WKTYPE/>
<DOCUMENT_ID>00003365.HST</DOCUMENT_ID>
<HISTORY_INT_CODE>0x0004469a</HISTORY_INT_CODE>
<DATE_AMENDED>
<DAY>17</DAY>
<MONTH>02</MONTH>
<YEAR>2006</YEAR>
</DATE_AMENDED>
<TIME_CREATED>10:36:32</TIME_CREATED>
<HISTORY_NO>37978</HISTORY_NO>
<POST_TRAY/>
<DOCUMENT_TYPE>U</DOCUMENT_TYPE>
<HS30>EOT3</HS30>
<HS31/>
<EXTRA_TEXT_VALUE>Copy_of_Registers_at_Land_Registry</EXTRA_TEXT_VALUE>
</HISTORY>
<HISTORY>
<DATE_INSERTED>
<DAY>16</DAY>
<MONTH>02</MONTH>
<YEAR>2006</YEAR>
</DATE_INSERTED>
<DESCRIPTION>Other Title Documents received</DESCRIPTION>
<EXTRA_TEXT>>></EXTRA_TEXT>
<TIME_USED/>
<TIME_CHARGE>0.00</TIME_CHARGE>
<TIME_COST>0.00</TIME_COST>
<CASE_HOLDER>Melissa Johnson</CASE_HOLDER>
<USER_ID>melissa</USER_ID>
<WKTYPE/>
<DOCUMENT_ID>00003363.HST</DOCUMENT_ID>
<HISTORY_INT_CODE>0x00044657</HISTORY_INT_CODE>
<DATE_AMENDED>
<DAY>16</DAY>
<MONTH>02</MONTH>
<YEAR>2006</YEAR>
</DATE_AMENDED>
<TIME_CREATED>10:38:54</TIME_CREATED>
<HISTORY_NO>37985</HISTORY_NO>
<POST_TRAY/>
<DOCUMENT_TYPE>U</DOCUMENT_TYPE>
<HS30>EOT5</HS30>
<HS31/>
<EXTRA_TEXT_VALUE>Decoded_Title_Document</EXTRA_TEXT_VALUE>
</HISTORY>
<SCHEDULE>
<Activity_code>EOT2-1</Activity_code>
<Description>Title Number Retrieved</Description>
<Target>
<Day>16</Day>
<Month>02</Month>
<Year>2006</Year>
</Target>
<Actual>
<Day>16</Day>
<Month>02</Month>
<Year>2006</Year>
</Actual>
<Deliverable>0.00</Deliverable>
</SCHEDULE>
<SCHEDULE>
<Activity_code>EOT3</Activity_code>
<Description>Office Copies Received</Description>
<Target>
<Day>16</Day>
<Month>02</Month>
<Year>2006</Year>
</Target>
</SCHEDULE>
<SCHEDULE>
<Activity_code>EOT4</Activity_code>
<Description>Plan received</Description>
<Target>
<Day>16</Day>
<Month>02</Month>
<Year>2006</Year>
</Target>
</SCHEDULE>
<SCHEDULE>
<Activity_code>EOT5</Activity_code>
<Description>Other Title Documents received</Description>
<Target>
<Day>20</Day>
<Month>02</Month>
<Year>2006</Year>
</Target>
<Deliverable>n</Deliverable>
</SCHEDULE>
I'm using a Foreach to iterate through the schedule then a nested foreach to iterate through the history.
The problem is that when I loop through the history I duplicate the entry I added when processing the schedules. I 've tried to check that the not(DOCUMENT_ID=$docid) but it doesnt seem to equate to true.
Code:
<xsl:for-each select="SCHEDULE">
<xsl:variable name="activitycode" select="Activity_code"/>
<xsl:variable name="docid" select="//HISTORY[HS30=$activitycode]/DOCUMENT_ID"/>
<!--script>alert('<xsl:value-of select="$docid"/>');</script-->
<tr>
<td><xsl:value-of select="Description"/></td>
</tr>
<xsl:variable name="history" select="//HISTORY[HS30=$activitycode]"/>
<xsl:for-each select="$history">
<xsl:if test="not($history/DOCUMENT_ID)=$docid)">
<script>alert('<xsl:value-of select="$docid"/> <xsl:value-of select="DOCUMENT_ID"/> ');</script>
<tr>
<td height="22" valign="middle">
<a><xsl:attribute name="href">?function=document_run&document=DELIVERABLE&owner_code=<xsl:value-of select="$owner_int_code"/>&owner_type=case&xsl=activities&field@code_TF01=<xsl:value-of select="$activitycode"/>&case_int_code=<xsl:value-of select="$owner_int_code"/>&act=<xsl:value-of select="DESCRIPTION"/>&sale=<xsl:value-of select="$sale"/>&return_params=true&session_key=<xsl:value-of select="$sessionkey"/>&name=<xsl:value-of select="$name"/>&role=<xsl:value-of select="$role"/></xsl:attribute><xsl:value-of select="DESCRIPTION"/><xsl:if test="not(EXTRA_TEXT_VALUE='')"> - <xsl:value-of select="EXTRA_TEXT_VALUE"/></xsl:if></a>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
I cant get not($history/DOCUMENT_ID)=$docid) to evaluate as I would expect. I thought it would mean that if a history item is found to have the document id of the schedule added then dont allow it to be added. Does anyone know what I might be doing wrong or can suggest and alternative please? I'd be very grateful.
I've also tried using a key and generate-id() but I'm not that experienced with them.
Thanks
Matt