Merging using XSLT - xslt-1.0

Below is my input XML. Here Each X_DLV_TAB_ITEM have multiple RL_DETAILS that again have multiple RL_DETAILS_ITEM. Each X_DLV_TAB_ITEM contains TYPE.
My requirement is if TYPE is same for two or more X_DLV_TAB_ITEM then only one X_DLV_TAB_ITEM should get created which will contain all the RL_DETAILS_ITEM with same TYPE and for the ones with different TYPE need to follow the rest.
INPUT:
<X_DLV_TAB>
<X_DLV_TAB_ITEM>
<TYPE>A</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689764</DELIVERY_ID>
<NAME>46689764</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460996</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>11</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.2</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>5</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460997</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>5.28333</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.12</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>3</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
<X_DLV_TAB_ITEM>
<TYPE>A</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689764</DELIVERY_ID>
<NAME>46689764</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460993</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>17.6111</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.4</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>12</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460994</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>33</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.6</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>15</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460995</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>26.4</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.48</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>10</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
<X_DLV_TAB_ITEM>
<TYPE>B</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689766</DELIVERY_ID>
<NAME>46689766</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460993</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>17.6111</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.4</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>10</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
<X_DLV_TAB_ITEM>
<TYPE>C</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689767</DELIVERY_ID>
<NAME>46689767</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460995</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>26.4</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.48</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>150</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
</X_DLV_TAB>
OUTPUT:
<X_DLV_TAB>
<X_DLV_TAB_ITEM>
<TYPE>A</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689764</DELIVERY_ID>
<NAME>46689764</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460996</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>11</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.2</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>5</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460997</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>5.28333</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.12</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>3</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460993</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>17.6111</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.4</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>10</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460994</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>33</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.6</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>15</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460995</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>26.4</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.48</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>12</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
<X_DLV_TAB_ITEM>
<TYPE>B</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689766</DELIVERY_ID>
<NAME>46689766</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460993</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>17.6111</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.4</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>10</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
<X_DLV_TAB_ITEM>
<TYPE>C</TYPE>
<TRANSACTION_CODE>RC</TRANSACTION_CODE>
<DELIVERY_ID>46689767</DELIVERY_ID>
<NAME>46689767</NAME>
<RL_DETAILS>
<RL_DETAILS_ITEM>
<DELIVERY_DETAIL_ID>14460995</DELIVERY_DETAIL_ID>
<GROSS_WEIGHT>26.4</GROSS_WEIGHT>
<WEIGHT_UOM_CODE>LB</WEIGHT_UOM_CODE>
<VOLUME>0.48</VOLUME>
<VOLUME_UOM_CODE>CF</VOLUME_UOM_CODE>
<REQUESTED_QUANTITY>150</REQUESTED_QUANTITY>
</RL_DETAILS_ITEM>
</RL_DETAILS>
</X_DLV_TAB_ITEM>
</X_DLV_TAB>
My Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="first_of_source" match="X_DLV_TAB/X_DLV_TAB_ITEM[not(preceding-sibling::X_DLV_TAB_ITEM/TYPE = TYPE)]" use="TYPE"/>
<xsl:key name="same_source" match="X_DLV_TAB/X_DLV_TAB_ITEM/RL_DETAILS" use="RL_DETAILS_ITEM"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="X_DLV_TAB">
<xsl:copy>
<xsl:apply-templates select="key('first_of_source', X_DLV_TAB_ITEM/TYPE)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="RL_DETAILS">
<xsl:copy>
<xsl:apply-templates select="key('same_source', RL_DETAILS_ITEM)/RL_DETAILS_ITEM"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
And this code is not generating the required output. I am using XSLT 1.0.

AFAICT, you want to do:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="item-by-type" match="X_DLV_TAB_ITEM" use="TYPE"/>
<xsl:template match="/X_DLV_TAB">
<xsl:copy>
<!-- create a group for each distinct TYPE -->
<xsl:for-each select="X_DLV_TAB_ITEM[count(. | key('item-by-type', TYPE)[1]) = 1]">
<xsl:copy>
<!-- copy common elements -->
<xsl:copy-of select="*[not(self::RL_DETAILS)]"/>
<RL_DETAILS>
<!-- copy all RL_DETAILS_ITEMs of current group-->
<xsl:copy-of select="key('item-by-type', TYPE)/RL_DETAILS/RL_DETAILS_ITEM"/>
</RL_DETAILS>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Note that this assumes that all X_DLV_TAB_ITEMs with the same TYPE have the same data, except for the contents of RL_DETAILS. Therefore, all data except the contents of RL_DETAILS is copied from the first X_DLV_TAB_ITEM of each group. Then the RL_DETAILS element is populated by the RL_DETAILS_ITEMs of the entire group.

Related

Loop Through Collection of XML Records in SQL

I have a dataset that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<process xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<return>
<approved>
<callbackTable>
<tableRow max="100" value="10" selectedRow="true" maxRow="112.0">
<tableCell term="72" selectedCell="false" maxCell="73">
<number>21.7</number>
</tableCell>
<tableCell term="74" selectedCell="true" maxCell="75">
<number>21.7</number>
</tableCell>
</tableRow>
<tableRow max="200" value="15" selectedRow="false" maxRow="113.0">
<tableCell term="76" selectedCell="false" maxCell="77">
<number>14.5</number>
</tableCell>
<tableCell term="78" selectedCell="false" maxCell="79">
<number>22.5</number>
</tableCell>
</tableRow>
<tableRow max="300" value="20" selectedRow="false" maxRow="114.0">
<tableCell term="80" selectedCell="false" maxCell="81">
<number>14.6</number>
</tableCell>
<tableCell term="82" selectedCell="false" maxCell="83">
<number>15.7</number>
</tableCell>
</tableRow>
</callbackTable>
</approved>
</return>
</process>
I need to be able to loop through the callbackTable entries and add them to a table named Options.
Here is what I need the data to ultimately look like in the Options table.
Id
Max
Value
SelectedRow
MaxRow
Term
SelectedCell
MaxCell
Number
1
100
10
true
112.0
72
false
73
21.7
2
100
10
true
112.0
74
true
75
21.7
3
200
15
false
113.0
76
false
77
14.5
4
200
15
false
113.0
78
false
79
22.5
5
300
20
false
114.0
80
false
81
14.6
6
300
20
false
114.0
82
false
83
15.7
(Note that the Id column is an identity key and does not need to be populated)
The tricky part is that I don't know exactly how many rows or how many cells are in the callbackTable collection so I will need to loop through the results and insert based on the number of items in the collection.
I could really use some help as I'm not entirely sure where to start.
Thanks in advance!
If you can change the encoding in the XML processing instruction to utf-16 or omit it, try the set-based query below. Note the Id column of the target table is omitted from the column list so that SQL Server will assign the IDENTITY value.
DECLARE #xml xml =
<process xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<return>
<approved>
<callbackTable>
<tableRow max="100" value="10" selectedRow="true" maxRow="112.0">
<tableCell term="72" selectedCell="false" maxCell="73">
<number>21.7</number>
</tableCell>
<tableCell term="74" selectedCell="true" maxCell="75">
<number>21.7</number>
</tableCell>
</tableRow>
<tableRow max="200" value="15" selectedRow="false" maxRow="113.0">
<tableCell term="76" selectedCell="false" maxCell="77">
<number>14.5</number>
</tableCell>
<tableCell term="78" selectedCell="false" maxCell="79">
<number>22.5</number>
</tableCell>
</tableRow>
<tableRow max="300" value="20" selectedRow="false" maxRow="114.0">
<tableCell term="80" selectedCell="false" maxCell="81">
<number>14.6</number>
</tableCell>
<tableCell term="82" selectedCell="false" maxCell="83">
<number>15.7</number>
</tableCell>
</tableRow>
</callbackTable>
</approved>
</return>
</process>';
INSERT INTO dbo.TargetTable([Max],[Value],[SelectedRow],[MaxRow],[Term],[SelectedCell],[MaxCell],[Number])
SELECT
tableRow.value('data(./#max)', 'varchar(10)')
,tableRow.value('data(./#value)', 'int')
,tableRow.value('data(./#selectedRow)', 'varchar(10)')
,tableRow.value('data(./#maxRow)', 'decimal(10,1)')
,tableCell.value('data(./#term)', 'int')
,tableCell.value('data(./#selectedCell)', 'varchar(10)')
,tableCell.value('data(./#maxCell)', 'int')
,tableCell.value('./number[1]', 'decimal(10,1)')
FROM #xml.nodes('//tableRow') AS tableRow(tableRow)
CROSS APPLY tableRow.nodes('//tableCell') AS tableCell(tableCell);

libreoffice convert docx to odt lost bookmark

I use the following command converting a docx to odt, one of the bookmarks get lost.
"libreoffice --headless --convert-to odt output.docx --outdir ./"
----- output.docx
------- following bookmarks was created by python-docx
<w:p w14:paraId="5D4F37CC" w14:textId="1FE5A142" w:rsidR="007E1B42" w:rsidRDefault="00356283" w:rsidP="00356283">
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>a</w:t>
</w:r>
<w:bookmarkStart w:id="0" w:name="xxbookmark4"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:p w14:paraId="34895FBC" w14:textId="518CEA5B" w:rsidR="007E1B42" w:rsidRDefault="00CF7EC0" w:rsidP="00CF7EC0">
<w:pPr>
<w:pStyle w:val="Heading2"/>
</w:pPr>
<w:r>
<w:t>b</w:t>
</w:r>
<w:bookmarkStart w:id="0" w:name="xxbookmark5"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
...
<w:p>
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>Index1</w:t>
</w:r>
<w:bookmarkStart w:id="0" w:name="xxbookmark34"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:p>
<w:r>
<w:t>--a......................................................</w:t>
</w:r>
<w:hyperlink w:anchor="xxbookmark4" w:history="1">
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>AAA</w:t>
</w:r>
</w:hyperlink>
</w:p>
<w:p>
<w:r>
<w:t>----b................................................</w:t>
</w:r>
<w:hyperlink w:anchor="xxbookmark5" w:history="1">
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>AAA</w:t>
</w:r>
</w:hyperlink>
</w:p>
<w:p>
<w:r>
<w:t>--Index1.......................................</w:t>
</w:r>
<w:hyperlink w:anchor="xxbookmark34" w:history="1">
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>AAA</w:t>
</w:r>
</w:hyperlink>
</w:p>
<w:p/>
---- output.odt
<text:h text:style-name="Heading_20_1" text:outline-level="1">
a
<text:bookmark text:name="xxbookmark4"/>
</text:h>
<text:h text:style-name="Heading_20_2" text:outline-level="2">
b
<text:bookmark text:name="xxbookmark5"/>
</text:h>
...
<text:h text:style-name="P1" text:outline-level="1">Index1</text:h>
# issue here: xxbookmark34 is lost.
Index1 was created using python-docx, the other two headings are just edit manually in Word.
Anybody can help, or give some hint.
I compared the xml file in docx and can not find any different between the "Index1" and other two.

Parse xml file in pandas

I have this xml file (it's called "LogReg.xml" and it contains some information about a logistic regression (I am interested in the name of the features and their coefficient - I'll explain in more detail below):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PMML xmlns="http://www.dmg.org/PMML-4_4" xmlns:data="http://jpmml.org/jpmml-model/InlineTable" version="4.4">
<Header>
<Application name="JPMML-SkLearn" version="1.6.35"/>
<Timestamp>2022-02-15T09:44:54Z</Timestamp>
</Header>
<MiningBuildTask>
<Extension name="repr">PMMLPipeline(steps=[('classifier', LogisticRegression())])</Extension>
</MiningBuildTask>
<DataDictionary>
<DataField name="Target" optype="categorical" dataType="integer">
<Value value="0"/>
<Value value="1"/>
</DataField>
<DataField name="const" optype="continuous" dataType="double"/>
<DataField name="grade" optype="continuous" dataType="double"/>
<DataField name="emp_length" optype="continuous" dataType="double"/>
<DataField name="dti" optype="continuous" dataType="double"/>
<DataField name="Orig_FicoScore" optype="continuous" dataType="double"/>
<DataField name="inq_last_6mths" optype="continuous" dataType="double"/>
<DataField name="acc_open_past_24mths" optype="continuous" dataType="double"/>
<DataField name="mort_acc" optype="continuous" dataType="double"/>
<DataField name="mths_since_recent_bc" optype="continuous" dataType="double"/>
<DataField name="num_rev_tl_bal_gt_0" optype="continuous" dataType="double"/>
<DataField name="percent_bc_gt_75" optype="continuous" dataType="double"/>
</DataDictionary>
<RegressionModel functionName="classification" algorithmName="sklearn.linear_model._logistic.LogisticRegression" normalizationMethod="logit">
<MiningSchema>
<MiningField name="Target" usageType="target"/>
<MiningField name="const"/>
<MiningField name="grade"/>
<MiningField name="emp_length"/>
<MiningField name="dti"/>
<MiningField name="Orig_FicoScore"/>
<MiningField name="inq_last_6mths"/>
<MiningField name="acc_open_past_24mths"/>
<MiningField name="mort_acc"/>
<MiningField name="mths_since_recent_bc"/>
<MiningField name="num_rev_tl_bal_gt_0"/>
<MiningField name="percent_bc_gt_75"/>
</MiningSchema>
<Output>
<OutputField name="probability(0)" optype="continuous" dataType="double" feature="probability" value="0"/>
<OutputField name="probability(1)" optype="continuous" dataType="double" feature="probability" value="1"/>
</Output>
<RegressionTable intercept="0.8064694059338298" targetCategory="1">
<NumericPredictor name="const" coefficient="0.8013433785974717"/>
<NumericPredictor name="grade" coefficient="0.9010481046582982"/>
<NumericPredictor name="emp_length" coefficient="0.9460686056314133"/>
<NumericPredictor name="dti" coefficient="0.5117062988491518"/>
<NumericPredictor name="Orig_FicoScore" coefficient="0.07944303372859234"/>
<NumericPredictor name="inq_last_6mths" coefficient="0.20516234445402765"/>
<NumericPredictor name="acc_open_past_24mths" coefficient="0.4852503249658917"/>
<NumericPredictor name="mort_acc" coefficient="0.6673203078463711"/>
<NumericPredictor name="mths_since_recent_bc" coefficient="0.1962158305958366"/>
<NumericPredictor name="num_rev_tl_bal_gt_0" coefficient="0.12964661294856686"/>
<NumericPredictor name="percent_bc_gt_75" coefficient="0.04534570018290847"/>
</RegressionTable>
<RegressionTable intercept="0.0" targetCategory="0"/>
</RegressionModel>
</PMML>
I have parsed it using this code:
from lxml import objectify
path = 'LogReg.xml'
parsed = objectify.parse(open(path))
root = parsed.getroot()
data = []
if True:
for elt in root.RegressionModel.RegressionTable:
el_data = {}
for child in elt.getchildren():
el_data[child.tag] = child.text
data.append(el_data)
perf = pd.DataFrame(data)
I am interested in parsing this bit:
<RegressionTable intercept="0.8064694059338298" targetCategory="1">
<NumericPredictor name="const" coefficient="0.8013433785974717"/>
<NumericPredictor name="grade" coefficient="0.9010481046582982"/>
<NumericPredictor name="emp_length" coefficient="0.9460686056314133"/>
<NumericPredictor name="dti" coefficient="0.5117062988491518"/>
<NumericPredictor name="Orig_FicoScore" coefficient="0.07944303372859234"/>
<NumericPredictor name="inq_last_6mths" coefficient="0.20516234445402765"/>
<NumericPredictor name="acc_open_past_24mths" coefficient="0.4852503249658917"/>
<NumericPredictor name="mort_acc" coefficient="0.6673203078463711"/>
<NumericPredictor name="mths_since_recent_bc" coefficient="0.1962158305958366"/>
<NumericPredictor name="num_rev_tl_bal_gt_0" coefficient="0.12964661294856686"/>
<NumericPredictor name="percent_bc_gt_75" coefficient="0.04534570018290847"/>
</RegressionTable>
so that I can build the following dictionary:
myDict = {
"const : 0.8013433785974717,
"grade" : 0.9010481046582982,
"emp_length" : 0.9460686056314133,
"dti" : 0.5117062988491518,
"Orig_FicoScore" : 0.07944303372859234,
"inq_last_6mths" : 0.20516234445402765,
"acc_open_past_24mths" : 0.4852503249658917,
"mort_acc" : 0.6673203078463711,
"mths_since_recent_bc" : 0.1962158305958366,
"num_rev_tl_bal_gt_0" : 0.12964661294856686,
"percent_bc_gt_75" : 0.04534570018290847
}
Basically, in the dictionary the Key is the name of the feature and the value is the coefficient of the logistic regression.
Please can anyone help me with the code?
I'm not sure you need pandas for this, but you do need to handle the namespaces in your xml.
Try something along these lines:
myDict = {}
#register the namespace
ns = {'xx': 'http://www.dmg.org/PMML-4_4'}
#you could collapse the next two into one line, but I believe it's clearer this way
rt = root.xpath('//xx:RegressionTable[.//xx:NumericPredictor]',namespaces=ns)[0]
nps = rt.xpath('./xx:NumericPredictor',namespaces=ns)
for np in nps:
myDict[np.attrib['name']]=np.attrib['coefficient']
myDict
The output should be your expected output.

Ebay motors api - Category is not valid. ID 33562

Trying to post the item in ebay motors using ebay api call - AddItem. It throws me an error saying as below. Could you please show some light on this.
Note - I am able to add the item manually in ebay motors with compatability. I fetched the item details (which is added manually) using the api call - GetItem. Placed the same details in the AddItem api call. Though it got failed with below error.
<ShortMessage>Category is not valid.</ShortMessage>
<LongMessage>The category is not valid, select another category.</LongMessage>
<ErrorCode>107</ErrorCode>
<SeverityCode>Error</SeverityCode>
<ErrorClassification>RequestError</ErrorClassification>
Request message is
<?xml version="1.0" encoding="UTF-8"?>
<AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>********PG1QKFIlH****</eBayAuthToken>
</RequesterCredentials>
<Version>967</Version>
<ErrorLanguage>en_US</ErrorLanguage>
<WarningLevel>High</WarningLevel>
<Item>
<Title>Sample ebay motor brake fitment product</Title>
<Description>Hummer Truck Right Side Mirror</Description>
<StartPrice currencyID="USD">236.0</StartPrice>
<Country>US</Country>
<Currency>USD</Currency>
<ListingDuration>Days_7</ListingDuration>
<Location>Los Angeles, California</Location>
<DispatchTimeMax>2</DispatchTimeMax>
<ConditionID>1000</ConditionID>
<PaymentMethods>PayPal</PaymentMethods>
<PayPalEmailAddress>w*****1#gmail.com</PayPalEmailAddress>
<Quantity>1</Quantity>
<PrimaryCategory>
<CategoryID>33562</CategoryID>
</PrimaryCategory>
<PictureDetails>
<GalleryType>Gallery</GalleryType>
<GalleryURL>http://****/z/QJsAAOSwXSJXPHk~/$_1.JPG?set_id=880000500F</GalleryURL>
<PhotoDisplay>PicturePack</PhotoDisplay>
<PictureURL>http://*****/z/QJsAAOSwXSJXPHk~/$_1.JPG?set_id=880000500F</PictureURL>
</PictureDetails>
<ShippingDetails>
<ApplyShippingDiscount>false</ApplyShippingDiscount>
<GlobalShipping>true</GlobalShipping>
<CalculatedShippingRate>
<WeightMajor measurementSystem="English" unit="lbs">0</WeightMajor>
<WeightMinor measurementSystem="English" unit="oz">0</WeightMinor>
</CalculatedShippingRate>
<ShippingServiceOptions>
<ShippingService>ShippingMethodStandard</ShippingService>
<ShippingServiceCost currencyID="USD">0.0</ShippingServiceCost>
<ShippingServicePriority>1</ShippingServicePriority>
<ExpeditedService>false</ExpeditedService>
<ShippingTimeMin>1</ShippingTimeMin>
<ShippingTimeMax>6</ShippingTimeMax>
<FreeShipping>true</FreeShipping>
</ShippingServiceOptions>
<ShippingType>Flat</ShippingType>
<ThirdPartyCheckout>false</ThirdPartyCheckout>
<TaxTable>
<TaxJurisdiction>
<JurisdictionID>CA</JurisdictionID>
<SalesTaxPercent>10.0</SalesTaxPercent>
<ShippingIncludedInTax>false</ShippingIncludedInTax>
</TaxJurisdiction>
</TaxTable>
<ShippingDiscountProfileID>0</ShippingDiscountProfileID>
<InternationalShippingDiscountProfileID>0</InternationalShippingDiscountProfileID>
<ExcludeShipToLocation>Alaska/Hawaii</ExcludeShipToLocation>
<ExcludeShipToLocation>US Protectorates</ExcludeShipToLocation>
<ExcludeShipToLocation>APO/FPO</ExcludeShipToLocation>
<ExcludeShipToLocation>Africa</ExcludeShipToLocation>
<ExcludeShipToLocation>Asia</ExcludeShipToLocation>
<ExcludeShipToLocation>Central America and Caribbean</ExcludeShipToLocation>
<ExcludeShipToLocation>Europe</ExcludeShipToLocation>
<ExcludeShipToLocation>Middle East</ExcludeShipToLocation>
<ExcludeShipToLocation>Oceania</ExcludeShipToLocation>
<ExcludeShipToLocation>Southeast Asia</ExcludeShipToLocation>
<ExcludeShipToLocation>South America</ExcludeShipToLocation>
<ExcludeShipToLocation>BM</ExcludeShipToLocation>
<ExcludeShipToLocation>GL</ExcludeShipToLocation>
<ExcludeShipToLocation>MX</ExcludeShipToLocation>
<ExcludeShipToLocation>PM</ExcludeShipToLocation>
<ExcludeShipToLocation>PO Box</ExcludeShipToLocation>
<SellerExcludeShipToLocationsPreference>true</SellerExcludeShipToLocationsPreference>
</ShippingDetails>
<ReturnPolicy>
<RefundOption>MoneyBack</RefundOption>
<Refund>Money Back</Refund>
<ReturnsWithinOption>Days_14</ReturnsWithinOption>
<ReturnsWithin>14 Days</ReturnsWithin>
<ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
<ReturnsAccepted>Returns Accepted</ReturnsAccepted>
<ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
<ShippingCostPaidBy>Buyer</ShippingCostPaidBy>
<RestockingFeeValue>No</RestockingFeeValue>
<RestockingFeeValueOption>NoRestockingFee</RestockingFeeValueOption>
</ReturnPolicy>
<ItemCompatibilityList>
<Compatibility>
<NameValueList/>
<NameValueList>
<Name>Year</Name>
<Value>2008</Value>
</NameValueList>
<NameValueList>
<Name>Make</Name>
<Value>Workhorse Custom Chassis</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>R26</Value>
</NameValueList>
<NameValueList>
<Name>Trim</Name>
<Value>Base Motor Home - Stripped Chassis</Value>
</NameValueList>
<NameValueList>
<Name>Engine</Name>
<Value>8.1L 496Cu. In. V8 GAS OHV Naturally Aspirated</Value>
</NameValueList>
<CompatibilityNotes></CompatibilityNotes>
</Compatibility>
<Compatibility>
<NameValueList/>
<NameValueList>
<Name>Year</Name>
<Value>1998</Value>
</NameValueList>
<NameValueList>
<Name>Make</Name>
<Value>Advance Mixer</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>M</Value>
</NameValueList>
<NameValueList>
<Name>Trim</Name>
<Value>Base Straight Truck - Half Cab</Value>
</NameValueList>
<NameValueList>
<Name>Engine</Name>
<Value>-- DIESEL</Value>
</NameValueList>
<CompatibilityNotes></CompatibilityNotes>
</Compatibility>
<Compatibility>
<NameValueList/>
<NameValueList>
<Name>Year</Name>
<Value>1988</Value>
</NameValueList>
<NameValueList>
<Name>Make</Name>
<Value>Yugo</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>GVS</Value>
</NameValueList>
<NameValueList>
<Name>Trim</Name>
<Value>Base Hatchback 3-Door</Value>
</NameValueList>
<NameValueList>
<Name>Engine</Name>
<Value>1.1L 1116CC l4 GAS SOHC Naturally Aspirated</Value>
</NameValueList>
<CompatibilityNotes></CompatibilityNotes>
</Compatibility>
<Compatibility>
<NameValueList/>
<NameValueList>
<Name>Year</Name>
<Value>1963</Value>
</NameValueList>
<NameValueList>
<Name>Make</Name>
<Value>Wolseley</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>1500</Value>
</NameValueList>
<NameValueList>
<Name>Trim</Name>
<Value>Base</Value>
</NameValueList>
<NameValueList>
<Name>Engine</Name>
<Value>1.5L 1489CC 91Cu. In. l4 GAS OHV Naturally Aspirated</Value>
</NameValueList>
<CompatibilityNotes></CompatibilityNotes>
</Compatibility>
<Compatibility>
<NameValueList/>
<NameValueList>
<Name>Year</Name>
<Value>1928</Value>
</NameValueList>
<NameValueList>
<Name>Make</Name>
<Value>Yellow Cab</Value>
</NameValueList>
<NameValueList>
<Name>Model</Name>
<Value>Model D-1</Value>
</NameValueList>
<NameValueList>
<Name>Trim</Name>
<Value>Base</Value>
</NameValueList>
<NameValueList>
<Name>Engine</Name>
<Value>--</Value>
</NameValueList>
<CompatibilityNotes></CompatibilityNotes>
</Compatibility>
</ItemCompatibilityList>
</Item>
</AddItemRequest>
Make sure that you using the 100 as the value of the HTTP header X-EBAY-API-SITEID. This ensures that your request is routed to the eBay motors site where the category is valid. Using 0 in the header routes the request to ebay.com where the category is not valid.

XSLT2.0 grouping based on three fields

<passengergroup>
<passengerList>
<passDetails>
<route>LONDON</route>
<lastname>RAY</lastname>
</passDetails>
<seatDetails>
<SeatNo>1A</SeatNo>
</seatDetails>
<customervalue>AB</customervalue>
</passengerList
<passengerList>
<passDetails>
<route>LONDON</route>
<lastname>RAY</lastname>
</passDetails>
<seatDetails>
<SeatNo>1B</SeatNo>
</seatDetails>
<customervalue>good</customervalue>
</passengerList
<passengerList>
<passDetails>
<route>DELHI</route>
<lastname>RAY</lastname>
</passDetails>
<seatDetails>
<SeatNo>2C</SeatNo>
</seatDetails>
<customervalue>BC</customervalue>
</passengerList>
<passengerList>
<passDetails>
<route>DELHI</route>
<lastname>RAY</lastname>
</passDetails>
<seatDetails>
<SeatNo>2D</SeatNo>
</seatDetails>
<customervalue>okey</customervalue>
</passengerList>
</passengergroup>
<xsl:for-each select="passengergroup/passengerList">
<xsl:if test="customervalue='good'
<xsl:value-of select="route"/><xsl:text> </xsl:text>
<xsl:value-of select="customervalue"/><xsl:text> </xsl:text>
<xsl:value-of select="seatDetails/SeatNo"/>
</for-each>
<xsl:for-each select="passengergroup/passengerList">
<xsl:if test="customervalue='ok'
<xsl:value-of select="route"/><xsl:text> </xsl:text>
<xsl:value-of select="customervalue"/><xsl:text> </xsl:text>
<xsl:value-of select="seatDetails/SeatNo"/>
</for-each>
Output
It will produce output like this
LONDON good 1A
LONDON good 1B
DELHI okey 2C
DELHI okey 2D
But i need the output like this
LONDON good 1A 1B
DELHI okey 2C 2D
If 'LONDON good 'is repeating many times,it has to be printed only once.but we got to repeat the seat no like' 1A 1B 1C 1D 1F 2G and so on'.i AM using xslt2.0 AND MY OUTPUT TYPE IS text. Thing is no need to display the items many times
I tried lot ..not able to figure out the solutions please help me out.
IMO your input xml doesn't correspond to desired output (e.g. there is only one LONDON with customervalue = good. But may be I don't understand well what you needs. But following xslt could make a job.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:apply-templates select="passengergroup" />
</xsl:template>
<xsl:template match="passengergroup">
<xsl:for-each-group select="passengerList" group-by="concat(passDetails/route, ' ', customervalue)">
<xsl:value-of select="current-grouping-key()" />
<xsl:text> </xsl:text>
<xsl:value-of select="current-group()/seatDetails/SeatNo" separator=" " />
<xsl:value-of select="'
'" />
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
For input
<?xml version="1.0" encoding="UTF-8"?>
<passengergroup>
<passengerList>
<passDetails>
<route>LONDON</route>
<lastname>RAY</lastname>
</passDetails>
<seatDetails>
<SeatNo>1A</SeatNo>
</seatDetails>
<customervalue>good</customervalue>
</passengerList>
<passengerList>
<passDetails>
<route>LONDON</route>
<lastname>RAY</lastname>
</passDetails>
<seatDetails>
<SeatNo>1B</SeatNo>
</seatDetails>
<customervalue>good</customervalue>
</passengerList>
<passengerList>
<passDetails>
<route>DELHI</route>
<lastname>RAY</lastname>
</passDetails>
<seatDetails>
<SeatNo>2C</SeatNo>
</seatDetails>
<customervalue>BC</customervalue>
</passengerList>
<passengerList>
<passDetails>
<route>DELHI</route>
<lastname>RAY</lastname>
</passDetails>
<seatDetails>
<SeatNo>2D</SeatNo>
</seatDetails>
<customervalue>okey</customervalue>
</passengerList>
</passengergroup>
it produces following output
LONDON good 1A 1B
DELHI BC 2C
DELHI okey 2D