Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old March 20th, 2018, 01:34 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Compare Two Parent Tags

Hello.

I have the following XML code:
Code:
<CRCDATA>
    <CRCDATALINE>
        <CRC>SOM2</CRC>
        <PDFPRINT>N</PDFPRINT>
        <CRCSTATERC>G57</CRCSTATERC>
    </CRCDATALINE>
    <CRCDATALINE>
        <CRC>SOM5</CRC>
        <PDFPRINT>Y</PDFPRINT>
        <CRCSTATERC>G57</CRCSTATERC>
    </CRCDATALINE>
</CRCDATA>
I need to print all <CRCSTATERC> where <PDFPRINT>Y and <CRCSTATERC> not equal to the <CRCSTATERC> in a parent tag.

In my XML code this would be "G57" from the second <CRCDATALINE>.

I have the following XSLT code:
Code:
<xsl:for-each select="CRCDATA/CRCDATALINE">
    <xsl:if test="CRCSTATERC!='' and (PDFPRINT='Y' or not(PDFPRINT))">
        <xsl:if test="not(CRCSTATERC[.=parent::*/preceding-sibling::*/CRCSTATERC]) and HERE'S WHERE I'M STUCK!">
            <xsl:value-of select="CRCSTATERC"/>
        </xsl:if>
    </xsl:if>
</xsl:for-each>
I don't know how to code the second test (HERE'S WHERE I'M STUCK!) to see if the same position of <PDFPRINT> (in the first occurrence of <CRCDATALINE>) is Y. If it is Y, then I would not print the second "G57". If it's N, then second "G57" would print. How would I allow <PDFPRINT> to not be present (as in older versions of my XML files)?

Any help will be greatly appreciated!

Thanks,
Rita

Last edited by ritagr; March 20th, 2018 at 01:42 PM..
 
Old March 20th, 2018, 02:07 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, Rita, I'm having trouble understanding the question.

Perhaps your requirement is:

For a CRCDATALINE, print (something) if (a) PDFPRINT is "Y" or absent, and (b) there is no preceding-sibling CRCDATALINE having (the same value of CRCSTATERC and (PDFPRINT="Y" or absent))

That would be:

Code:
<xsl:for-each select="CRCDATALINE[not(PDFPRINT='N') and
  not(preceding-sibling::CDCDATALINE[not(PDFPRINT='N') and CRCSTATERC=current()/CRCSTATERC])]">...
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
ritagr (March 20th, 2018)
 
Old March 20th, 2018, 02:34 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Oh my goodness!!
Thank you Michael - your answer was perfect.
Learn something new every day!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Static Meta Tags (same meta-tags for multiple pages) dan_333 Classic ASP Basics 1 August 19th, 2012 07:03 PM
looping through siblings to change br tags to p tags fistofzen XSLT 0 September 19th, 2011 10:40 AM
Compare RockBal XSLT 2 November 25th, 2010 12:43 AM
Compare current value with previous parent node ratjetoes XSLT 2 July 17th, 2008 06:15 AM
compare these date fields and compare and get the susanring Oracle 1 July 24th, 2006 04:58 PM





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