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
------------------------------
Original Message:
Sent: Thu August 19, 2021 04:50 PM
From: Jon Peck
Subject: spss.EvaluateXPath and document order
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.
--
Original Message:
Sent: 8/16/2021 8:13:00 AM
From: Kees Smit
Subject: RE: spss.EvaluateXPath and document order
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
Original Message:
Sent: Mon August 16, 2021 05:55 AM
From: Kees Smit
Subject: spss.EvaluateXPath and document order
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
------------------------------
#SPSSStatistics