Need help to find a correct Xpath for XSLT code










1















I have an XML below and need a correct xpath for the following condition:



Look for Phone_Device_Type_ID = Cell # 1
Look for Communication_Usage_Type_ID = WORK
Display Formatted_Phone


My xpath:



wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/wd:Phone_Data[
wd:Phone_Device_Type_Reference/wd:ID='Cell # 1'
]/wd:Usage_Data[wd:Type_Data/wd:Type_Reference/wd:ID='WORK']/@wd:Formatted_Phone


Sample XML



<wd:Phone_Data wd:Formatted_Phone="+1 (847) 8675309">
<wd:Country_ISO_Code>USA</wd:Country_ISO_Code>
<wd:International_Phone_Code>1</wd:International_Phone_Code>
<wd:Area_Code>847</wd:Area_Code>
<wd:Phone_Number>8675309</wd:Phone_Number>
<wd:Phone_Device_Type_Reference>
<wd:ID wd:type="WID">1cfe702a6234015468e3527fd07c1001</wd:ID>
<wd:ID wd:type="Phone_Device_Type_ID">Cell # 1</wd:ID>
</wd:Phone_Device_Type_Reference>
<wd:Usage_Data wd:Public="1">
<wd:Type_Data wd:Primary="0">
<wd:Type_Reference>
<wd:ID wd:type="WID">1f27f250dfaa4724ab1e1617174281e4</wd:ID>
<wd:ID wd:type="Communication_Usage_Type_ID">WORK</wd:ID>
</wd:Type_Reference>
</wd:Type_Data>
</wd:Usage_Data>
</wd:Phone_Data>
<wd:Phone_Data wd:Formatted_Phone="+1 (847) 8675309">
<wd:Country_ISO_Code>USA</wd:Country_ISO_Code>
<wd:International_Phone_Code>1</wd:International_Phone_Code>
<wd:Area_Code>847</wd:Area_Code>
<wd:Phone_Number>8675309</wd:Phone_Number>
<wd:Phone_Device_Type_Reference>
<wd:ID wd:type="WID">1cfe702a6234015468e3527fd07c1001</wd:ID>
<wd:ID wd:type="Phone_Device_Type_ID">Cell # 1</wd:ID>
</wd:Phone_Device_Type_Reference>
<wd:Usage_Data wd:Public="1">
<wd:Type_Data wd:Primary="0">
<wd:Type_Reference>
<wd:ID wd:type="WID">1f27f250dfaa4724ab1e1617174281e4</wd:ID>
<wd:ID wd:type="Communication_Usage_Type_ID">HOME</wd:ID>
</wd:Type_Reference>
</wd:Type_Data>
</wd:Usage_Data>
</wd:Phone_Data>









share|improve this question




























    1















    I have an XML below and need a correct xpath for the following condition:



    Look for Phone_Device_Type_ID = Cell # 1
    Look for Communication_Usage_Type_ID = WORK
    Display Formatted_Phone


    My xpath:



    wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/wd:Phone_Data[
    wd:Phone_Device_Type_Reference/wd:ID='Cell # 1'
    ]/wd:Usage_Data[wd:Type_Data/wd:Type_Reference/wd:ID='WORK']/@wd:Formatted_Phone


    Sample XML



    <wd:Phone_Data wd:Formatted_Phone="+1 (847) 8675309">
    <wd:Country_ISO_Code>USA</wd:Country_ISO_Code>
    <wd:International_Phone_Code>1</wd:International_Phone_Code>
    <wd:Area_Code>847</wd:Area_Code>
    <wd:Phone_Number>8675309</wd:Phone_Number>
    <wd:Phone_Device_Type_Reference>
    <wd:ID wd:type="WID">1cfe702a6234015468e3527fd07c1001</wd:ID>
    <wd:ID wd:type="Phone_Device_Type_ID">Cell # 1</wd:ID>
    </wd:Phone_Device_Type_Reference>
    <wd:Usage_Data wd:Public="1">
    <wd:Type_Data wd:Primary="0">
    <wd:Type_Reference>
    <wd:ID wd:type="WID">1f27f250dfaa4724ab1e1617174281e4</wd:ID>
    <wd:ID wd:type="Communication_Usage_Type_ID">WORK</wd:ID>
    </wd:Type_Reference>
    </wd:Type_Data>
    </wd:Usage_Data>
    </wd:Phone_Data>
    <wd:Phone_Data wd:Formatted_Phone="+1 (847) 8675309">
    <wd:Country_ISO_Code>USA</wd:Country_ISO_Code>
    <wd:International_Phone_Code>1</wd:International_Phone_Code>
    <wd:Area_Code>847</wd:Area_Code>
    <wd:Phone_Number>8675309</wd:Phone_Number>
    <wd:Phone_Device_Type_Reference>
    <wd:ID wd:type="WID">1cfe702a6234015468e3527fd07c1001</wd:ID>
    <wd:ID wd:type="Phone_Device_Type_ID">Cell # 1</wd:ID>
    </wd:Phone_Device_Type_Reference>
    <wd:Usage_Data wd:Public="1">
    <wd:Type_Data wd:Primary="0">
    <wd:Type_Reference>
    <wd:ID wd:type="WID">1f27f250dfaa4724ab1e1617174281e4</wd:ID>
    <wd:ID wd:type="Communication_Usage_Type_ID">HOME</wd:ID>
    </wd:Type_Reference>
    </wd:Type_Data>
    </wd:Usage_Data>
    </wd:Phone_Data>









    share|improve this question


























      1












      1








      1








      I have an XML below and need a correct xpath for the following condition:



      Look for Phone_Device_Type_ID = Cell # 1
      Look for Communication_Usage_Type_ID = WORK
      Display Formatted_Phone


      My xpath:



      wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/wd:Phone_Data[
      wd:Phone_Device_Type_Reference/wd:ID='Cell # 1'
      ]/wd:Usage_Data[wd:Type_Data/wd:Type_Reference/wd:ID='WORK']/@wd:Formatted_Phone


      Sample XML



      <wd:Phone_Data wd:Formatted_Phone="+1 (847) 8675309">
      <wd:Country_ISO_Code>USA</wd:Country_ISO_Code>
      <wd:International_Phone_Code>1</wd:International_Phone_Code>
      <wd:Area_Code>847</wd:Area_Code>
      <wd:Phone_Number>8675309</wd:Phone_Number>
      <wd:Phone_Device_Type_Reference>
      <wd:ID wd:type="WID">1cfe702a6234015468e3527fd07c1001</wd:ID>
      <wd:ID wd:type="Phone_Device_Type_ID">Cell # 1</wd:ID>
      </wd:Phone_Device_Type_Reference>
      <wd:Usage_Data wd:Public="1">
      <wd:Type_Data wd:Primary="0">
      <wd:Type_Reference>
      <wd:ID wd:type="WID">1f27f250dfaa4724ab1e1617174281e4</wd:ID>
      <wd:ID wd:type="Communication_Usage_Type_ID">WORK</wd:ID>
      </wd:Type_Reference>
      </wd:Type_Data>
      </wd:Usage_Data>
      </wd:Phone_Data>
      <wd:Phone_Data wd:Formatted_Phone="+1 (847) 8675309">
      <wd:Country_ISO_Code>USA</wd:Country_ISO_Code>
      <wd:International_Phone_Code>1</wd:International_Phone_Code>
      <wd:Area_Code>847</wd:Area_Code>
      <wd:Phone_Number>8675309</wd:Phone_Number>
      <wd:Phone_Device_Type_Reference>
      <wd:ID wd:type="WID">1cfe702a6234015468e3527fd07c1001</wd:ID>
      <wd:ID wd:type="Phone_Device_Type_ID">Cell # 1</wd:ID>
      </wd:Phone_Device_Type_Reference>
      <wd:Usage_Data wd:Public="1">
      <wd:Type_Data wd:Primary="0">
      <wd:Type_Reference>
      <wd:ID wd:type="WID">1f27f250dfaa4724ab1e1617174281e4</wd:ID>
      <wd:ID wd:type="Communication_Usage_Type_ID">HOME</wd:ID>
      </wd:Type_Reference>
      </wd:Type_Data>
      </wd:Usage_Data>
      </wd:Phone_Data>









      share|improve this question
















      I have an XML below and need a correct xpath for the following condition:



      Look for Phone_Device_Type_ID = Cell # 1
      Look for Communication_Usage_Type_ID = WORK
      Display Formatted_Phone


      My xpath:



      wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/wd:Phone_Data[
      wd:Phone_Device_Type_Reference/wd:ID='Cell # 1'
      ]/wd:Usage_Data[wd:Type_Data/wd:Type_Reference/wd:ID='WORK']/@wd:Formatted_Phone


      Sample XML



      <wd:Phone_Data wd:Formatted_Phone="+1 (847) 8675309">
      <wd:Country_ISO_Code>USA</wd:Country_ISO_Code>
      <wd:International_Phone_Code>1</wd:International_Phone_Code>
      <wd:Area_Code>847</wd:Area_Code>
      <wd:Phone_Number>8675309</wd:Phone_Number>
      <wd:Phone_Device_Type_Reference>
      <wd:ID wd:type="WID">1cfe702a6234015468e3527fd07c1001</wd:ID>
      <wd:ID wd:type="Phone_Device_Type_ID">Cell # 1</wd:ID>
      </wd:Phone_Device_Type_Reference>
      <wd:Usage_Data wd:Public="1">
      <wd:Type_Data wd:Primary="0">
      <wd:Type_Reference>
      <wd:ID wd:type="WID">1f27f250dfaa4724ab1e1617174281e4</wd:ID>
      <wd:ID wd:type="Communication_Usage_Type_ID">WORK</wd:ID>
      </wd:Type_Reference>
      </wd:Type_Data>
      </wd:Usage_Data>
      </wd:Phone_Data>
      <wd:Phone_Data wd:Formatted_Phone="+1 (847) 8675309">
      <wd:Country_ISO_Code>USA</wd:Country_ISO_Code>
      <wd:International_Phone_Code>1</wd:International_Phone_Code>
      <wd:Area_Code>847</wd:Area_Code>
      <wd:Phone_Number>8675309</wd:Phone_Number>
      <wd:Phone_Device_Type_Reference>
      <wd:ID wd:type="WID">1cfe702a6234015468e3527fd07c1001</wd:ID>
      <wd:ID wd:type="Phone_Device_Type_ID">Cell # 1</wd:ID>
      </wd:Phone_Device_Type_Reference>
      <wd:Usage_Data wd:Public="1">
      <wd:Type_Data wd:Primary="0">
      <wd:Type_Reference>
      <wd:ID wd:type="WID">1f27f250dfaa4724ab1e1617174281e4</wd:ID>
      <wd:ID wd:type="Communication_Usage_Type_ID">HOME</wd:ID>
      </wd:Type_Reference>
      </wd:Type_Data>
      </wd:Usage_Data>
      </wd:Phone_Data>






      xml xslt xpath






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 3:29









      Mads Hansen

      44.9k1195122




      44.9k1195122










      asked Nov 15 '18 at 1:17









      Yaqoob AliYaqoob Ali

      61




      61






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You were close, but the way it was written your XPath was expecting the @wd:Formatted_Phone attribute to be attached to the wd:Usage_Data element. You want to select that element on the wd:Phone_Data element and move the wd:Usage_data inside of the predicate filter on the wd:Phone_Data element.



          The following selects the @wd:Formatted_Phone value of the wd:Phone_Data element that has elements meeting your criteria (with additional predicates to target the wd:ID elements with the specified @wd:type value.



          wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/
          wd:Phone_Data[
          wd:Phone_Device_Type_Reference/wd:ID[@wd:type='Phone_Device_Type_ID']='Cell # 1' and
          wd:Usage_Data/wd:Type_Data/wd:Type_Reference/wd:ID[@wd:type='Communication_Usage_Type_ID']='WORK'
          ]/@wd:Formatted_Phone





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311102%2fneed-help-to-find-a-correct-xpath-for-xslt-code%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You were close, but the way it was written your XPath was expecting the @wd:Formatted_Phone attribute to be attached to the wd:Usage_Data element. You want to select that element on the wd:Phone_Data element and move the wd:Usage_data inside of the predicate filter on the wd:Phone_Data element.



            The following selects the @wd:Formatted_Phone value of the wd:Phone_Data element that has elements meeting your criteria (with additional predicates to target the wd:ID elements with the specified @wd:type value.



            wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/
            wd:Phone_Data[
            wd:Phone_Device_Type_Reference/wd:ID[@wd:type='Phone_Device_Type_ID']='Cell # 1' and
            wd:Usage_Data/wd:Type_Data/wd:Type_Reference/wd:ID[@wd:type='Communication_Usage_Type_ID']='WORK'
            ]/@wd:Formatted_Phone





            share|improve this answer





























              0














              You were close, but the way it was written your XPath was expecting the @wd:Formatted_Phone attribute to be attached to the wd:Usage_Data element. You want to select that element on the wd:Phone_Data element and move the wd:Usage_data inside of the predicate filter on the wd:Phone_Data element.



              The following selects the @wd:Formatted_Phone value of the wd:Phone_Data element that has elements meeting your criteria (with additional predicates to target the wd:ID elements with the specified @wd:type value.



              wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/
              wd:Phone_Data[
              wd:Phone_Device_Type_Reference/wd:ID[@wd:type='Phone_Device_Type_ID']='Cell # 1' and
              wd:Usage_Data/wd:Type_Data/wd:Type_Reference/wd:ID[@wd:type='Communication_Usage_Type_ID']='WORK'
              ]/@wd:Formatted_Phone





              share|improve this answer



























                0












                0








                0







                You were close, but the way it was written your XPath was expecting the @wd:Formatted_Phone attribute to be attached to the wd:Usage_Data element. You want to select that element on the wd:Phone_Data element and move the wd:Usage_data inside of the predicate filter on the wd:Phone_Data element.



                The following selects the @wd:Formatted_Phone value of the wd:Phone_Data element that has elements meeting your criteria (with additional predicates to target the wd:ID elements with the specified @wd:type value.



                wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/
                wd:Phone_Data[
                wd:Phone_Device_Type_Reference/wd:ID[@wd:type='Phone_Device_Type_ID']='Cell # 1' and
                wd:Usage_Data/wd:Type_Data/wd:Type_Reference/wd:ID[@wd:type='Communication_Usage_Type_ID']='WORK'
                ]/@wd:Formatted_Phone





                share|improve this answer















                You were close, but the way it was written your XPath was expecting the @wd:Formatted_Phone attribute to be attached to the wd:Usage_Data element. You want to select that element on the wd:Phone_Data element and move the wd:Usage_data inside of the predicate filter on the wd:Phone_Data element.



                The following selects the @wd:Formatted_Phone value of the wd:Phone_Data element that has elements meeting your criteria (with additional predicates to target the wd:ID elements with the specified @wd:type value.



                wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/
                wd:Phone_Data[
                wd:Phone_Device_Type_Reference/wd:ID[@wd:type='Phone_Device_Type_ID']='Cell # 1' and
                wd:Usage_Data/wd:Type_Data/wd:Type_Reference/wd:ID[@wd:type='Communication_Usage_Type_ID']='WORK'
                ]/@wd:Formatted_Phone






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 15 '18 at 3:34

























                answered Nov 15 '18 at 3:27









                Mads HansenMads Hansen

                44.9k1195122




                44.9k1195122





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311102%2fneed-help-to-find-a-correct-xpath-for-xslt-code%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo