Xpath Syntax accessing two data sources - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Xpath Syntax accessing two data sources

Last post 02-07-2012 08:41 AM by Hilary Stoupa. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 02-06-2012 08:12 AM

    Xpath Syntax accessing two data sources

     I am currenlty building a demo Expenses Form using InfoPath to work with SharePoint. While selecting a category for the type of claim along with the approitate sub category there is an associated tax code which tells the system how much VAT was charged on each item.

    I have written the cascading drop down lists using XML to allow the selects to be filtered for each category. These each then produce a tax code. I am trying to take this code back to its value in the XML document to use in the mathmatical formula to work out VAT. 

    Currenlty I have this XPath expression:

    xdXDocument:GetDOM("Categories")/ClaimCategories/TaxCode/code[@TaxID = "xdXDocument:get-DOM()/my:myFields/my:SubCategory1"]

    If I replace xdXDocument:get-DOM()/my:myFields/my:SubCategory1 with T2, etc it will show me the value I want.  Also if I put xdXDocument:get-DOM()/my:myFields/my:SubCategory1 in the expression box T2 is printed out.  However when I have the whole formula I get no values.  I think I have made a fairly basic syntax error, but can't work it out.

     This is the XML Document I have written for the Dropdown boxs and to hold the Tax values:

     <ClaimCategories>
    <TaxCode>
    <code TaxID = "T0">0</code>
    <code TaxID = "T1">0.20</code>
    <code TaxID = "T2">0.20</code>
    <code TaxID = "T3">0.20</code>
    </TaxCode>
    <Categories>
        <category CatID="X">Travelling</category>
        <category CatID="Y">Accommodation</category>
        <category CatID="Z">Subsistence</category>
        <category CatID="A">Telephone and Mobile</category>
        <category CatID="B">Advertising</category>
        <category CatID="C">Training Material</category>
        <category CatID="D">UK Entertainment</category>
        <category CatID="E">Meeting Expenses</category>
        <category CatID="F">Printing and Stationery</category>
        <category CatID="G">Postage and Carriage</category>
        <category CatID="H">Subscriptions</category>
        <category CatID="I">Staff Events</category>
    </Categories>
    <SubCategories>
        <product CatID="X" ProdID="1" TaxID="T2">Plane/Train/Boat</product>
        <product CatID="X" ProdID="2" TaxID="T1">Parking</product>
        <product CatID="X" ProdID="3" TaxID="T1">Petrol</product>
        <product CatID="X" ProdID="4" TaxID="T1">Taxi</product>
        <product CatID="X" ProdID="5" TaxID="T1">Tolls</product>
        <product CatID="Y" ProdID="1" TaxID="T2">Hotel</product>
        <product CatID="Y" ProdID="2" TaxID="T2">Bed and Breakfast</product>
        <product CatID="Y" ProdID="3" TaxID="T2">Guest House</product>
        <product CatID="Y" ProdID="4" TaxID="T2">Rented</product>
        <product CatID="Z" ProdID="1" TaxID="T1">Breakfast</product>
        <product CatID="Z" ProdID="2" TaxID="T1">Lunch</product>
        <product CatID="Z" ProdID="3" TaxID="T1">Dinner</product>
        <product CatID="Z" ProdID="4" TaxID="T0">Tips</product>
        <product CatID="A" ProdID="1" TaxID="T1">International</product>
        <product CatID="A" ProdID="2" TaxID="T1">Fax</product>
        <product CatID="A" ProdID="3" TaxID="T1">Internet 3G</product>
        <product CatID="B" ProdID="1" TaxID="T1">Web Site</product>
        <product CatID="B" ProdID="2" TaxID="T1">Directory Listing</product>
        <product CatID="B" ProdID="3" TaxID="T1">Social Media Promotion</product>
        <product CatID="C" ProdID="1" TaxID="T1">Staff</product>
        <product CatID="C" ProdID="2" TaxID="T1">Equipment</product>
        <product CatID="D" ProdID="1" TaxID="T0">Entertainment</product>
        <product CatID="E" ProdID="1" TaxID="T1">Meeting</product>
        <product CatID="F" ProdID="1" TaxID="T1">Photocopying</product>
        <product CatID="F" ProdID="2" TaxID="T1">Ink cartridges</product>
        <product CatID="G" ProdID="1" TaxID="T2">Postage</product>
        <product CatID="G" ProdID="2" TaxID="T1">Carriage</product>
        <product CatID="H" ProdID="1" TaxID="T1">Magazines</product>
        <product CatID="H" ProdID="2" TaxID="T1">Books</product>
        <product CatID="H" ProdID="3" TaxID="T1">Journals</product>
        <product CatID="I" ProdID="1" TaxID="T1">Christmas Party</product>
     </SubCategories>
    </ClaimCategories>

     

     

    -->

    Filed under: , ,
  • 02-06-2012 08:38 AM In reply to

    Re: Xpath Syntax accessing two data sources

    Hi - a couple of questions.

    It appears that for your subcategory dropdown you are using the TaxID for the value - that may cause issues for you, since that is not unique for each SubCategories/product. In fact, it appears that the unique entity is the product itself. Is there a reason you are using TaxID for the value?

    And, I guess, another question / comment - it seems the form could be greatly simplified by using a repeating node for the schema, rather than having category 1 -9, VAT 1-9, etc. Is there a reason to use a non-repeating schema here?

    At any rate, it seems this might get your code, if the main data source subcategory field is using product for its value instead of tax id:

    xdXDocument:GetDOM("Categories")/ClaimCategories/TaxCode/code[@TaxID = ../../SubCategories/product/@TaxID[.. = xdXDocument:get-DOM()/my:myFields/my:SubCategory1]]

     

    Hilary Stoupa

  • 02-06-2012 08:39 AM In reply to

    Re: Xpath Syntax accessing two data sources

    The problem here is that you've put "xdXDocument:get-DOM()/my:myFields/my:SubCategory1" in quotes, so that part is being treated as a constant value instead of a formula.  How's this:

    xdXDocument:GetDOM("Categories")/ClaimCategories/TaxCode/code[@TaxID = xdXDocument:get-DOM()/my:myFields/my:SubCategory1]

    On a separate note,for a form like this, I think you should definitely be using a repeating table, and I recommend giving that a try.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-06-2012 08:56 AM In reply to

    Re: Xpath Syntax accessing two data sources

     Thank you for that it has fixed the problem I was having.

     

    The reason I didn't use repeating tables was because I picked up InfoPath on Friday after being thrown onto a project which uses it and needed to make a demo form quickly. However is there a reason I should be using repeating tables for this?

     

    Thank you in advance and again.

  • 02-06-2012 10:23 AM In reply to

    Re: Xpath Syntax accessing two data sources

    Any time I see a schema that has a field repeated with a slightly different name, I generally think a repeating node would work better.

    It may make things a little trickier for you - you'll need to use the current() function in your XPath to get the TaxID based on the SubCategory, for example, but it means you wouldn't have to change 9 controls, or create 9 different expressions. It also means you could allow your users to insert more or less than 9 rows, if desired.

    Hilary Stoupa

  • 02-07-2012 02:03 AM In reply to

    Re: Xpath Syntax accessing two data sources

     Hi thank you

     

    I will try using repeating fields to create this as it does sound a much better way. One quick question in the XPath where would I put the current() to get the TaxID?

  • 02-07-2012 08:41 AM In reply to

    Re: Xpath Syntax accessing two data sources

    Well, that depends on your data structure. But let's pretend that my:SubCategory is now inside a repeating group called "Expenses". You've got a repeating table bound to that group. You are putting an expression box in the repeating table that is going to show the code - so current() in this case refers to the current instance of the repeating group Expenses:

    xdXDocument:GetDOM("Categories")/ClaimCategories/TaxCode/code[@TaxID = current()/my:SubCategory]

    Hilary Stoupa

Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.