Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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: 100%
Activity: 100% Activity: 100% Activity: 100%
 
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
Reply With Quote
  #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: 100%
Activity: 100% Activity: 100% Activity: 100%
 
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)">
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:19 PM.


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