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 April 13th, 2010, 04:41 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Code To Use the Position Function

Hello.

I'll first show my XML code and will then place my question.

<RCDATALINE>
<TRC>90</TRC>
<OVERRIDE>Y</OVERRIDE>
</RCDATALINE>
<RCDATALINE>
<TRC>90</TRC>
<OVERRIDE>N</OVERRIDE>
</RCDATALINE>
<RCDATALINE>
<TRC>90</TRC>
<OVERRIDE>N</OVERRIDE>
</RCDATALINE>

I need to print the <TRC> value but only if it hasn't been printed before.
Also, if the OVERRIDE> value is Y, do not print <TRC>.
So, with the above XML, only the second <TRC> would print.

Within a for-each loop, I use preceding-sibling. My problem is that when I find a match for <TRC> in a previous sibling, that occurrence of the <OVERRIDE> needs to be N.

Here's the code that I currently have that needs to have to position() logic added to it.

<xsl:for-each select "RCDATALINE">
<xsl:when test="TRC[.!=''">
<xsl:if test="not (TRC[.=parent::*/preceding-sibling::*/TRC])
and OVERRIDE(position())[.!='Y']"> !!!!!HELP NEEDED HERE
<xsl:value-of select="TRC"/>
</xsl:if>
</xsl:when>
</xsl:for-each>

Any suggestions will be greatly appreciated!

Thanks,
Rita
 
Old April 13th, 2010, 05:55 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>I need to print the <TRC> value but only if it hasn't been printed before.

that is, if there is no preceding-sibling with the same TRC value and with OVERRIDE=N; or in XPath:

test="not(preceding-sibling::*[TRC = current()/TRC and OVERRIDE='N'])"
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 13th, 2010, 06:16 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Thanks Michael for your quick response.
I tried the code per your example and this time I am getting the <TRC> printing out (before it was not) but it's coming out twice.

I'll play around with it to see if I can get it to work.

-- Rita
 
Old April 13th, 2010, 07:30 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default FYI

I tried several combinations and the following one worked for me:
<xsl:if test="not(TRC[.=parent::*/preceding-sibling::*/TRC] and OVERRIDE='')">.

I now have to create various scenarios and hopefully they will work as required
 
Old April 14th, 2010, 12:01 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Not Working Under Different Conditions

My previous example of code worked for the sample XML code that I had in my initial question. However, for the following example, I get 90 twice when it should only display once.
The difference between this code and the original example is in the second <RCDATALINE>, <OVERRIDE> is Y whereas the original one is N.
NOTE: <TRC> must only print if <OVERRIDE> = N.

<RCDATALINE>
<TRC>90</TRC> -------------------- Should not print as <OVERRIDE> is Y
<OVERRIDE>Y</OVERRIDE>
</RCDATALINE>
<RCDATALINE>
<TRC>90</TRC> -------------------- Should not print as <OVERRIDE> is Y
<OVERRIDE>Y</OVERRIDE>
</RCDATALINE>
<RCDATALINE>
<TRC>90</TRC> -------------------- Should print as <OVERRIDE> is N and there is no previous 90 printed
<OVERRIDE>N</OVERRIDE>
</RCDATALINE>
<RCDATALINE>
<TRC>90</TRC> -------------------- Should not print as 90 from previous <TRC> already printed
<OVERRIDE>N</OVERRIDE>
</RCDATALINE>

So, the following line of code does not give me the required results.
<xsl:if test="not(TRC[.=parent::*/preceding-sibling::*/TRC] and OVERRIDE='')">.

I'm wondering if I should go the way of variables?!

Thanks,
Rita

Last edited by ritagr; April 14th, 2010 at 12:15 PM..
 
Old April 14th, 2010, 12:55 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Working Again

Well, after further playing around and using Michael's original suggestion I have some of my current test variations all working - except for the example above!!. Here's what's currently working for most of my examples (I added an OVERRIDE test to the initial test):

<xsl:when test="TRC[.!=''] and OVERRIDE[.!='Y']">
<xsl:if test="not(preceding-sibling::*[TRC = current()/TRC and OVERRIDE=''])">
<xsl:value-of select="TRC"/>

Last edited by ritagr; April 14th, 2010 at 01:12 PM..
 
Old April 14th, 2010, 01:25 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I can't see why you are testing OVERRIDE="" (empty string) when in all your examples OVERRIDE is either Y or N.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 14th, 2010, 01:30 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Oops - sorry.
It should be OVERRIDE='N'.

<xsl:when test="TRC[.!=''] and OVERRIDE[.!='Y']">
<xsl:if test="not(preceding-sibling::*[TRC = current()/TRC and OVERRIDE='N'])">
<xsl:value-of select="TRC"/>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Weekday name function in InfoPath, without code SilverSands_IT Infopath 0 November 24th, 2009 11:11 AM
Using the position() function... vb89 XSLT 9 October 15th, 2009 05:47 PM
VB code that calls a function mikefemi Beginning VB 6 1 January 11th, 2006 06:12 AM
Passing nodeset into position() function EstherMStrom XSLT 1 May 18th, 2005 04:04 PM
searching function using asp code ernafarizan Classic ASP Professional 1 May 8th, 2005 09:56 PM





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