Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 6th, 2020, 07:00 PM
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
  #2 (permalink)  
Old May 7th, 2020, 01:26 PM
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

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)">


Similar Threads
Thread Thread Starter Forum Replies Last Post
selecting sibling or cousin of current element shadi_a89 XSLT 0 April 3rd, 2014 09:46 AM
How to determine if an element value is unique? mphare XSLT 2 November 17th, 2008 12:12 PM
Problem adding element to the previous element dani1 XSLT 5 September 10th, 2008 01:38 AM
check name of the current node element in xml arunagottimukkala XSLT 19 October 19th, 2007 04:44 AM
Value of parent element of current-grouping-key() bonekrusher XSLT 2 September 9th, 2007 06:29 AM





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