XPath expression to select first instance of element in repeating parent node

huongvu91

New Member
I need to select the first instance of a node or element in a parent node that repeats. (My terminology may be incorrect). Tried adapting expressions from other posts here on stackoverflow to no avail.Basic situation: Working with a Person/Group picker in MS InfoPath. If someone picks more than one user in the picker field I want to reset it to the first chosen user. Trouble is that there are multiple pickers on the form that use a similar XML structure and so my XPath isn't working...InfoPath will handle the expressions and use rules to check for the existence of multiple users within the picker.Here is my sample XML followed by my failing expression:\[code\]<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.24" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///C:\Documents%20and%20Settings\Chris\Local%20Settings\Application%20Data\Microsoft\InfoPath\Designer3\35e8a7eff4a841a9\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?><my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls" xmlns:ma="http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes" xmlns:d="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields" xmlns:q="http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:dms="http://schemas.microsoft.com/office/2009/documentManagement/types" xmlns:tns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService" xmlns:s1="http://microsoft.com/wsdl/types/" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-09-06T15:09:43" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us"><my:section1> <my:group> <pc:Person xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls"> <pc:DisplayName>Green, John</pc:DisplayName> <pc:AccountId>DOMAIN\John.Green</pc:AccountId> <pc:AccountType>User</pc:AccountType> </pc:Person><pc:Person xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls"> <pc:DisplayName>Smith, John</pc:DisplayName> <pc:AccountId>DOMAIN\john.smith</pc:AccountId> <pc:AccountType>User</pc:AccountType></pc:Person> </my:group></my:section1><my:section2> <my:group> <pc:Person xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls"> <pc:DisplayName>Public, John</pc:DisplayName> <pc:AccountId>DOMAIN\John.Q.Public</pc:AccountId> <pc:AccountType>User</pc:AccountType> </pc:Person><pc:Person xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls"> <pc:DisplayName>Doe, John</pc:DisplayName> <pc:AccountId>DOMAIN\John.Doe</pc:AccountId> <pc:AccountType>User</pc:AccountType></pc:Person> </my:group></my:section2></my:myFields>\[/code\]The following expression returns both DOMAIN\John.Green and DOMAIN\John.Smith...\[code\]/descendant::my:section1/my:group/pc:Person/pc:DisplayName[1]\[/code\]Close but no cigar.I need two separate expressions; one that selects DOMAIN\John.Green and one that selects DOMAIN\John.Q.Public.
 
Back
Top