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 July 7th, 2013, 06:57 PM
Registered User
 
Join Date: Jul 2013
Posts: 6
Thanks: 1
Thanked 1 Time in 1 Post
Default Printing adjacent values when the condition is met in XSLT

<accountList>
<account>
<Title>Mr</Title>
<firstName>Richard</firstName>
<lastName>John</lastName>
<city>london</city>
<accNo>16</accNo>
</account>
<account>
<Title>Mr</Title>
<firstName>xxx</firstName>
<lastName>John</lastName>
<city>London</city>
<accNo>17</accNo>
</account>

<account>
<Title>Mr</Title>
<firstName>Hewit</firstName>
<lastName>John</lastName>
<city>london</city>
<accNo>20</accNo>
</account>
<account>
<Title>Mr</Title>
<firstName>xxx</firstName>
<lastName>John</lastName>
<city>london</city>
<accNo>21</accNo>
</account>
</accountList>

Output required:

If more than one person have the same last name(like Richard John & Hewit John) and their first names are XXX,

16 Richard John 17 (xxx for the Richard John, is more important to bring it here ') The 16 and 17 are accNo.
20 Hewit John 21 (xxx for the Hewit John,21(accNo)

Its working fine for the one element, ie <account> . If i have more one lastname my logic is not working. My problem is if i have more than one lastname,its simply not printing the result. Its unable to find the correct accNo for the corresponding lastName and firstName as well. Please help me out.

My Code:

<xsl:variable name="exstacc">
<xsl:for-each select="//accountList/account">
<xsl:if test="firstName='xxx'">
<xsl:value-of select="accNo"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="accLastname">
<xsl:for-each select="//accountList/account">
<xsl:if test="firstName='xxx'">
<xsl:value-of select="lastName"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>

<xsl:choose>
<xsl:when test="firstName='xxx' '">
<xsl:if test="lastName=$accLastname">
<xsl:text>EXTRA ACCS(S)</xsl:text>
<xsl:text> </xsl:text>
<xsl:value-of select="$exstacc"/>
</xsl:if>
</xsl:when>
</xsl:choose>

Last edited by santhakumar; July 8th, 2013 at 07:17 AM.. Reason: Description is not specific
 
Old July 7th, 2013, 07:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to put a little more effort into describing the specification of the problem. Please try to write in whole sentences - there's no 140-character limit here. At present your description is far too cryptic, so it's hard to work out what the problem is.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old July 8th, 2013, 07:19 AM
Registered User
 
Join Date: Jul 2013
Posts: 6
Thanks: 1
Thanked 1 Time in 1 Post
Default

I have updated my question .Please have a look Mhkay.
 
Old July 8th, 2013, 09:06 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If I understand your specification correctly, you want to output one entry for each customer, where a customer is defined as a group of adjacent account elements such that the surname within the group matches, and the first name in every account except the first is "xxx". (There's a lot of guess work in extracting that specification from your examples so I might well have got it wrong.)

So that's something like

Code:
<xsl:template match="accountList">
  <xsl:for-each-group select="account" 
    group-starting-with="*[firstName != 'xxx' or lastName != preceding-sibling::*[1]/lastName]">
    <xsl:value-of select="current-group()[1]/(accNo, lastName, firstName),
           current-group()[position() gt 1]/accNo, '&#xa;'"/>
  </xsl:for-each-group>
</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old July 9th, 2013, 06:23 AM
Registered User
 
Join Date: Jul 2013
Posts: 6
Thanks: 1
Thanked 1 Time in 1 Post
Default

Hi Mhkay,

Thanks for the reply. Your logic is correct. Its working fine. As you told that
I didnt clearly explained as well.
Clearly I have explained the problem as below,Please help me out
Code:
<Primary>
<Secondary>
            <AccountDetails>
                <Title>Mr</Title>
                <FirstName>JOHN</FirstName>
                <LastName>DONALD</LastName>
                <Gender>Male</Gender>
            </AccountDetails>
            <AccNoDetails>
                <accNo>025</accNo>
                <Reason>nothing</Reason>
             <PassengerStatus>
                <Active>true</Active>
            </PassengerStatus>
            <BookingDetails>
                <Reference>025</Reference>
                <activeCustomer>F</activeCustomer>
            </BookingDetails>
  <Secondary>
<Secondary>
             <AccountDetails>
                <Title>Mr</Title>
                <FirstName>XXX</FirstName>
                <LastName>DONALD</LastName>
                <Gender>Male</Gender>
            </AccountDetails>
            <AccNoDetails>
                <accNo>026</accNo>
                <Reason>nothing</Reason>
             <PassengerStatus>
                <Active>true</Active>
            </PassengerStatus>
            <BookingDetails>
                <Reference>026</Reference>
                <activeCustomer>F</activeCustomer>
            </BookingDetails>
  <Secondary>
<Secondary>
            <AccountDetails>
                <Title>Mr</Title>
                <FirstName>RICHARD</FirstName>
                <LastName>PARKER</LastName>
                <Gender>Male</Gender>
            </AccountDetails>
            <AccNoDetails>
                <accNo>025</accNo>
                <Reason>nothing</Reason>
             <PassengerStatus>
                <Active>true</Active>
            </PassengerStatus>
            <BookingDetails>
                <Reference>028</Reference>
                <activeCustomer>F</activeCustomer>
            </BookingDetails>
  <Secondary>
<Secondary>
             <AccountDetails>
                <Title>Mr</Title>
                <FirstName>ALAN</FirstName>
                <LastName>DONALD</LastName>
                <Gender>Male</Gender>
            </AccountDetails>
            <AccNoDetails>
                <accNo>030</accNo>
                <Reason>nothing</Reason>
             <PassengerStatus>
                <Active>true</Active>
            </PassengerStatus>
            <BookingDetails>
                <Reference>025</Reference>
                <activeCustomer>F</activeCustomer>
            </BookingDetails>
  <Secondary>
<Secondary>
             <AccountDetails>
                <Title>Mr</Title>
                <FirstName>xxx</FirstName>
                <LastName>DONALD</LastName>
                <Gender>Male</Gender>
            </AccountDetails>
            <AccNoDetails>
                <accNo>025</accNo>
                <Reason>nothing</Reason>
             <PassengerStatus>
                <Active>true</Active>
            </PassengerStatus>
            <BookingDetails>
                <Reference>031</Reference>
                <activeCustomer>F</activeCustomer>
            </BookingDetails>
  <Secondary>   

Required output.

AccNo FirstName LastName  Gender  ExtraAccNo

025    JOHN        DONALD    Male     ExtraAccNo:026    
028    RICHARD   PARKER     Male     
030    ALAN        DONALD    Male    ExtraAccNo:031
Note:
1.('ExtraAccNo' should be hardcoded)
2.(I wont print Hardcode 'ExtraAccNo' in the second row, because his first name doesnt have 'xxx' in the upcoming elements


'xxx' <secondary> element should be removed from the row,Just I used it for retrieving AccNo

Here based on conditions only i am displaying the Hardcoded 'ExtraAccNo:' and those corresponding AccNo.


The problem is I already done for-each for AccNo FirstName LastName Gender display.Because already I have done more conditions(code part). Is it possible bring the exact 'ExtraAccNo:AccNo' for the particular row?

conditions are explained in my last post.
The Following User Says Thank You to santhakumar For This Useful Post:
sen1953 (July 30th, 2013)
 
Old July 11th, 2013, 04:23 AM
Registered User
 
Join Date: Jul 2013
Posts: 6
Thanks: 1
Thanked 1 Time in 1 Post
Default Thanks Mhkay.I solved my issue by solution you provided

Thanks Mhkay.I solved my issue by solution you provided





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT - row numbers which met criteria lonas XSLT 5 June 21st, 2012 04:46 AM
need to add adjacent element(with their child nodes) in to single in XSLT xsltstarter XSLT 8 June 6th, 2012 10:13 AM
Hide any records that a condition is not met. tweeter85usn Access 0 March 23rd, 2012 03:57 PM
Plotting and Printing of Graphs from database values and user values in VB6 Olayiwola Ahmed Tijani VB How-To 0 February 10th, 2010 04:46 AM
XSLT:How to loop through nodes and retrieve attributes values based on some condition smandeh XSLT 2 March 24th, 2009 01:50 PM





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