SPSS Statistics

Expand all | Collapse all

spss.EvaluateXPath and document order

  • 1.  spss.EvaluateXPath and document order

    Posted Mon August 16, 2021 05:56 AM
    Hello all

    Needing to obtain the variable names together with the accompanying uncounted frequencies from a cTables pivot table I use
    the following Xpath expression:
    # I'm looking for variables not equal to "Contrast"
    # cmd contains the cTables command
    path = """outputTree//pivotTable[@subType= "Custom Table"]//group[@varName !="Contrast"and @variable = "true"]/@varName |"""
    path += """//pivotTable[@subType= "Custom Table"]//category[@text="Total"]/dimension[@axis="column"]//group[@text="1,00"]//cell[@text]/@number"""

    handle,failcode=spssaux.CreateXMLOutput(cmd, omsid='CTables', visible=False )
    result = spss.EvaluateXPath(handle, "/", path)
    I found this to work out OK, but I'm not sure whether the results are always guaranteed to be correct. It seems to depend on spss.EvaluateXPath always returning the expressions before and after the pipe symbol in the same order. I believe the same
    order is guaranteed using Xpath 2.0 but as far as I know spss.EvaluateXPath uses Xpath 1.0.

    Could somebody shed some light here?

    Thanks in advance


    ------------------------------
    Kees Smit
    ------------------------------


  • 2.  RE: spss.EvaluateXPath and document order

    Posted Mon August 16, 2021 08:13 AM
    Or would something like

    path = """outputTree//pivotTable[@subType= "Custom Table"]//group[@variable = "true"]//category[@text="Total"]/dimension//group[2]//cell/@number | """
    path += """ outputTree//pivotTable[@subType= "Custom Table"]//group[@variable = "true"]//category[@text="Total"]/dimension//group[2]//cell/preceding::category[@varName][1]/@varName"""

    be preferrable because this provides a direct link between the two elements?

    ------------------------------
    Kees Smit
    ------------------------------



  • 3.  RE: spss.EvaluateXPath and document order

    Posted Mon August 16, 2021 08:39 AM
    Probably this is better, but I would expect the order of the elements always to match the order in the xml document.  If you want to send me some code to generate a table (jkpeck@gmail.com), I could poke around a bit5.
    --





  • 4.  RE: spss.EvaluateXPath and document order

    Posted Thu August 19, 2021 04:52 PM
    I think either of these would be okay.  The path expression could be much simplified to
    //group[@variable="true"]//category[@text="Total"]//cell/@number

    You might be able to simplify this using the spssaux.GetValuesFromXmlWorkspace function and a little logic..  

    I would expect the order to be the same for both of the xml queries, but I have not used the previous qualifier, so it is just a guess.

    However, this is a pretty simple table, and capturing it as an OMS dataset would let you use regular SPSS syntax (or Python code) to extract the desired portions.

    Sorry for the delayed response.  Good luck.

    --





  • 5.  RE: spss.EvaluateXPath and document order

    Posted Fri August 20, 2021 09:39 AM
    Please, don't apologize for not instaneous responses, I'm very happy with the way you deal with our questions.

    Your simplified path shows numbers from both columns where I set out to retreive only the second column. I realize I can simply skip every other value, but I was trying to generate the most parsimonious path (if that's the right word for it) , just for the sake of it.

    I wasn't aware that spssaux.GetValuesFromXmlWorkspace is able to access other table elements than pure data. For example, I thought that with GetValuesFromXmlWorkspace you can retreive the frequencies, but not the variable lables. I'll look into that again.

    And thank you for your last suggestion. Looks promising.

    ------------------------------
    Kees Smit
    ------------------------------



  • 6.  RE: spss.EvaluateXPath and document order

    Posted Fri August 20, 2021 02:05 PM
    That function indeed doesn't show nondata column, but when using it, the syntax that generated the output is usually available in the program, so you would get the information from that.

    --