View Single Post
  #1 (permalink)  
Old May 6th, 2020, 07:00 PM
ritagr ritagr is offline
Authorized User
Points: 323, Level: 6
Points: 323, Level: 6 Points: 323, Level: 6 Points: 323, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Determine If Previous Element Matches Current Element

Hello,

I have the following XML code:
Code:
<doc>
  <EOB>
  <DETAILLINE>
    <SERVICE>SERVICE1</SERVICE>
    <RCDATA>
      <RCDATALINE>
        <RC>1A</RC>
        <TRC>36</TRC>
      </RCDATALINE>
    </RCDATA
  </DETAILLINE>
  <DETAILLINE>
    <SERVICE>SERVICE2</SERVICE>
    <RCDATA>
      <RCDATALINE>
        <RC>1A</RC>
        <TRC>36</TRC>
      </RCDATALINE>
    </RCDATA
  </DETAILLINE>
  <RCINFO>
    <RCLINE>
      <RCCODE>RC 1A</RCCODE>
      <RCEXPLANATION>
        <LINE>This is my explanation line</LINE>
      </RCEXPLANATION>
    </RCLINE>
  </RCINFO>
Here is what I need to accomplish:
For each unique <DETAILLINE><RCDATA><RCDATALINE><TRC>, I need to print out the value of <RCINFO><RCLINE><RCEXPLANATION><LINE> when the <DETAILLINE><RCDATA><RCDATALINE><RC> (1A) matches the
<RCINFO><RCLINE><RCCODE>(RC 1A).
I do preface the <DETAILLINE><RCDATA><RCDATALINE><RC> with "RC " so a match can be found.

NOTE: <DETAILLINE><RCDATA><RCDATALINE> can occur up to six times.

So from the above elements, I only need "This is my explanation line" to be printed once.

I'm using the following code which works when there are values only in the first <DETAILLINE><RCDATA><RCDATALINE>. However, when there are values in more than one of the six occurs, I do not get "This is my explanation line" printed.

Code:
<xsl:for-each select="/doc/EOB/DETAIL/DETAILLINE/RCDATA/RCDATALINE">
  <xsl:sort select="RC" order="ascending"/>			
  <xsl:variable name="varRCDATALINERC" select="RC"/>
  <xsl:variable name="varRCDATALINETRC" select="TRC"/>
  <xsl:variable name="varRCDATA" select="RC"/>
  <xsl:variable name="varRCCODEMatch" select="concat(substring(/doc/EOB/RCINFO/RCLINE[1]/RCCODE,1,3),RC)"/>
  <xsl:if test="RC[.!=''] and TRC[.=36]">					
    <xsl:if test="$varRCCODEMatch=following::*/RCCODE">		
      <xsl:if test="(not($varRCDATALINERC=ancestor-or self::*/preceding::*/RCDATALINE/RC)) and (not($varRCDATALINETRC=ancestor-or-self::*/preceding::*/RCDATALINE/TRC))">
I've been working on this most of the day and am stumped!
Any help will be greatly appreciated.

Thank you,
Rita