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 May 7th, 2012, 10:56 PM
Authorized User
 
Join Date: Feb 2012
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Default preceedign not working

I have an xml file that I am loading and want to ensure that I get only the unique values in the file. Hence, I am currently using:
<xsl:if test="not(preceding::c:FinancialAwardYear[local-name(..) = $fundName] and preceding::c:MPNID[text() = $response/c:MPNID/text()] and preceding::c:FinancialAwardNumber[text() = $response/../c:FinancialAwardNumber/text()])">

..however, I am not getting the unique values, rather getting one value of each matching type- typically the first one encountered. Doesn't the and make this a unique key? What should I be doing differently so as to consider all the above elements as a key so to speak when trying to obtain a unique value? I do not want to check just the preceding-sibling but rather everything that was before this element
Here is a sample file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<CommonRecord xmlns="http://www.ed.gov/FSA/COD/2010/v3.0d" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.ed.gov/FSA/COD/2010/v3.0d CommonRecord3.0d.xsd">
    <TransmissionData>
        <DocumentID>2010-09-30T02:55:48.6300000003</DocumentID>
        <CreatedDateTime>2010-09-30T04:33:58.86</CreatedDateTime>
        <Source>
            <COD>
                <RoutingID>00000001</RoutingID>
            </COD>
        </Source>
        <Destination>
            <School>
                <RoutingID>--------</RoutingID>
            </School>
        </Destination>
        <FullResponseCode>F</FullResponseCode>
    </TransmissionData>
    <ReportingSchool>
        <RoutingID>26321103</RoutingID>
        <AttendedSchool>
            <RoutingID>26321103</RoutingID>
            <Student>
                <Index>
                    <SSN>000112222</SSN>
                    <BirthDate>yyyy-mm-dd</BirthDate>
                    <LastName>GOSSARD</LastName>
                </Index>
                <Name>
                    <FirstName>STACY</FirstName>
                    <MiddleInitial>L</MiddleInitial>
                </Name>
                <DLSubsidized>
                    <AwardKey>01</AwardKey>
                    <FinancialAwardYear>2011</FinancialAwardYear>
                    <FinancialAwardNumber>001</FinancialAwardNumber>
                    <FinancialAwardID>000112222S11G12911001</FinancialAwardID>
                    <Response>
                        <ResponseCode>A</ResponseCode>
                        <EMPNIndicator>false</EMPNIndicator>
                        <MPNID>000112222M11G12911101</MPNID>
                        <MPNStatusCode>A</MPNStatusCode>
                        <MPNLinkIndicator>true</MPNLinkIndicator>
                        <MPNExpirationDate>2011-09-28</MPNExpirationDate>
                    </Response>
                </DLSubsidized>
                <DLUnsubsidized>
                    <AwardKey>01</AwardKey>
                    <FinancialAwardYear>2011</FinancialAwardYear>
                    <FinancialAwardNumber>002</FinancialAwardNumber>
                    <FinancialAwardID>000112222S11G12911001</FinancialAwardID>
                    <Response>
                        <ResponseCode>A</ResponseCode>
                        <EMPNIndicator>false</EMPNIndicator>
                        <MPNID>000112222M11G12911101</MPNID>
                        <MPNStatusCode>P</MPNStatusCode>
                        <MPNLinkIndicator>true</MPNLinkIndicator>
                        <MPNExpirationDate>2011-09-28</MPNExpirationDate>
                    </Response>
                </DLUnsubsidized>
                <Response>
                    <ResponseCode>A</ResponseCode>
                </Response>
            </Student>
            <Student>
                <Index>
                    <SSN>000112222</SSN>
                    <BirthDate>yyyy-mm-dd</BirthDate>
                    <LastName>GOSSARD</LastName>
                </Index>
                <Name>
                    <FirstName>STACY</FirstName>
                    <MiddleInitial>L</MiddleInitial>
                </Name>
                <DLSubsidized>
                    <AwardKey>01</AwardKey>
                    <FinancialAwardYear>2011</FinancialAwardYear>
                    <FinancialAwardNumber>001</FinancialAwardNumber>
                    <FinancialAwardID>000112222S11G12911001</FinancialAwardID>
                    <Response>
                        <ResponseCode>A</ResponseCode>
                        <EMPNIndicator>false</EMPNIndicator>
                        <MPNID>000112222M11G12911101</MPNID>
                        <MPNStatusCode>A</MPNStatusCode>
                        <MPNLinkIndicator>true</MPNLinkIndicator>
                        <MPNExpirationDate>2011-09-28</MPNExpirationDate>
                    </Response>
                </DLSubsidized>
                <Response>
                    <ResponseCode>A</ResponseCode>
                </Response>
            </Student>

            <Response>
                <ResponseCode>A</ResponseCode>
            </Response>
        </AttendedSchool>
        <Response>
            <ResponseCode>A</ResponseCode>
        </Response>
    </ReportingSchool>
    <Response>
        <DocumentTypeCode>PN</DocumentTypeCode>
        <DocumentStatusCode>A</DocumentStatusCode>
        <ProcessDate>2010-09-30</ProcessDate>
    </Response>
</CommonRecord>

Last edited by madowl; May 8th, 2012 at 12:50 AM..
 
Old May 8th, 2012, 03:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please try to reduce your question to something simpler. Your data is complex to understand, and you haven't shown any context for the XPath expression you are using (what is the context item at the time it is invoked? what are the values of $fundName and $response?)

preceding-sibling is appropriate if you want unique data among a set of sibling elements rather than uniqueness within the whole document; it's also more efficient than preceding in cases where both have the same meaning (because all the relevant elements are siblings).

However, even if you are stuck with using XSLT 1.0, this isn't an efficient way of handling de-duplication. Muenchian grouping is far better.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old May 8th, 2012, 04:48 AM
Authorized User
 
Join Date: Feb 2012
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Good evening Mr.Kay
The context of my xPath expression is within the FinancialAwardYear tag. I did read up on Muenchian grouping but wasnt quite sure on how to implement it in a scenario where I might require more than one element to be the key. ALternativley, I could use FinancialAwardID as the key and de-duplicate on that but as mentioned am a bit unsure of the Muenchian grouping

Last edited by madowl; May 8th, 2012 at 10:28 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
"If or" not working crabjoe Classic ASP Basics 3 March 12th, 2008 06:03 PM
window.opener working .... not working alyeng2000 Javascript How-To 5 January 5th, 2007 08:05 AM
Web.Config..Working or Not Working peace95 ASP.NET 1.0 and 1.1 Basics 1 September 18th, 2006 06:53 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM
Get Working Copy... not working Enkiel Classic ASP Basics 0 April 21st, 2004 01:41 PM





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