p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Determine If Previous Element Matches Current Element (http://p2p.wrox.com/showthread.php?t=100423)

ritagr May 6th, 2020 07:00 PM

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

ritagr May 7th, 2020 01:26 PM

Determine If Previous Element Matches Current Element
 
The following line of code allowed me to get the results I needed:
Code:

<xsl:if test="$varRCCODEMatch=following::*/RCCODE and not($varRCDATARC=ancestor::*/preceding::*/RC)">


All times are GMT -4. The time now is 07:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.