#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0

    XPath to join Parent and Child info


    Hi there

    I am trying to get a "join" of info stored in a parent node and its child nodes from a XML file. I need to get this done using only XPath as I am doing this in a Reporting tool which only allows XPath to work with XML data sources

    Problems is taht with XPath I am able to get the info stored in the parent node or the info stored in the child nodes, or even both ... but never at the same "level" and "together" which is what I need.

    Example
    <Servicio>
    <id_servicio>91</id_servicio>
    <Costes>
    <Fijos>78</Fijos>
    <Vables>87</Vables>
    </Costes>
    </Servicio>
    <Servicio>
    <id_servicio>92</id_servicio>
    <Costes>
    <Fijos>38</Fijos>
    <Vables>27</Vables>
    </Costes>
    </Servicio>

    If I use the XPath "/Servicio" I am able to get this:

    Id_Servicio
    91
    92

    other way If I use this XPath "/Servicio/Costes" result is::

    Fijos Vables
    78 87
    38 27

    However what I need to get is that the info stored in the parent and childs to appear in the same "row" of result, so I can use it and I can reflect it in the report:

    Id_Servicio Fijos Vables
    91 78 87
    92 38 27

    What I have been able to get was this "XPath":
    " /Servicio | /Servicio/Costes"

    Id_Servicio Fijos Vables
    91 - -
    ----------- 78 87
    92 - -
    ------------ 38 27


    But they are not in the same "row" and it is not valid for me to be used in the report.

    Any ideas please?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    24
    Rep Power
    0
    please try:

    to get w/o spaces in between - note single quotes in below
    Code:
    //Servicio/concat(.,'')
    with spaces, but this won't work for the general case
    Code:
    //Servicio/concat(./id_servicio, " ", ./Costes/Fijos, " ", ./Costes/Vables)
    this works for any child element names under Servicio but still have to adhere to expected structure of the text to be extracted
    Code:
    //Servicio/concat(./*[1], " ", ./*[2]/*[1], " ", ./*[2]/*[2])

IMN logo majestic logo threadwatch logo seochat tools logo