on 10-28-2021 1:12 PM
Hello,
Could you please tell me if it is possible to add an Xpath filter into a groovy script ?
Below is my sample in xml, I woul like to apply this filter : "//root/row[reason='ORDER_PREPARED']", then add root tags because they disappear when I apply a si,gle filter into sap cpi. My idea is to get the body into groovy script function, then apply a filter (//root/row[reason/text()='ORDER_PREPARED']) and finally add "<root>""</root>" tags.
<root>
<row>
<period_begin>2021-10-27 07:39:45.090462+00</period_begin>
<period_end/>
<line_id>6</line_id>
<reason>DLC_LIMIT_DAYS_PASSED</reason>
<product_sku>fromagers-halloumi</product_sku>
<sap_ship_to_id/>
<sap_ship_from_id>par-roty</sap_ship_from_id>
<total_stock>18</total_stock>
<sap_idn_id/>
<sap_idn_item_id/>
<sap_po_id/>
<sap_po_item_id/>
<quantity>2</quantity>
<channel>CAJOO</channel>
</row>
<row>
<period_begin>2021-10-27 07:39:45.090462+00</period_begin>
<period_end/>
<line_id>7</line_id>
<reason>DLC_LIMIT_DAYS_PASSED</reason>
<product_sku>pasquier-brioche-tressee-chocolat-630</product_sku>
<sap_ship_to_id/>
<sap_ship_from_id>par-sedaine</sap_ship_from_id>
<total_stock>8</total_stock>
<sap_idn_id/>
<sap_idn_item_id/>
<sap_po_id/>
<sap_po_item_id/>
<quantity>6</quantity>
<channel>CAJOO</channel>
</row>
</root>
Thanks for your help
Hi Pascal
You can do this easily in XSLT, using the technique I've described in this blog post. In your case, the stylesheet would look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode on-no-match="shallow-copy" />
<xsl:output method="xml" indent="yes" />
<xsl:template match="row[reason != 'ORDER_PREPARED']" />
</xsl:stylesheet>
With this, you can turn your Filter step and Content Modifier into a single XSLT mapping step.
Regards,
Morten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much for your answer but I would like this structure after the xsl if it is possible :
Output
<?xml version="1.0" encoding="UTF-8"?>
<root>
<row>
<period_begin>2021-10-27 07:39:45.090462+00</period_begin>
<period_end/>
<line_id>1</line_id>
<reason>ORDER_PREPARED</reason>
<product_sku>biof-pdm-complet-350</product_sku>
<sap_ship_to_id/>
<sap_ship_from_id>par-roty</sap_ship_from_id>
<total_stock>8</total_stock>
<sap_idn_id/>
<sap_idn_item_id/>
<sap_po_id/>
<sap_po_item_id/>
<quantity>5</quantity>
<channel>CAJOO</channel>
</row>
</root>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pascal
I don't quite understand that. What is the difference? Also, the XML you are showing here does not have the <root> element, which you mentioned that you added in a Content Modifier.
Regards,
Morten
P.S. Please use comments on answers instead of providing new answers. Right now you've answered your own question twice, which probably wasn't your intention 😄
Pascal, please explain further what the difference is. This output you are showing contains an SKU ("biof-pdm-complet-350"), which is not in any of the input you've shown here.
Ideally, update the question itself with the input and the expected output. Remember to use the CODE button to embed it.
Regards,
Morten
I would like to have in my output all the row node with chils nodes inside where "reason" = "ORDER_PREPARED" but inside a root tag, because on CPI when I use this filter : //root/row[reason/text()='ORDER_PREPARED'], my root tag disappear.
I would like to do this filter action whithout remove root tags, may be with a groovy script or an xsl.
Input <?xml version="1.0" encoding="UTF-8"?>
<root>
<row>
<period_begin>2021-10-27 07:39:45.090462+00</period_begin>
<period_end/>
<line_id>6</line_id>
<reason>DLC_LIMIT_DAYS_PASSED</reason>
<product_sku>fromagers-halloumi</product_sku>
<sap_ship_to_id/>
<sap_ship_from_id>par-roty</sap_ship_from_id>
<total_stock>18</total_stock>
<sap_idn_id/>
<sap_idn_item_id/>
<sap_po_id/>
<sap_po_item_id/>
<quantity>2</quantity>
<channel>CAJOO</channel>
</row>
<row>
<period_begin>2021-10-27 07:39:45.090462+00</period_begin>
<period_end/>
<line_id>7</line_id>
<reason>ORDER_PREPARED</reason>
<product_sku>pasquier-brioche-tressee-chocolat-630</product_sku>
<sap_ship_to_id/>
<sap_ship_from_id>par-sedaine</sap_ship_from_id>
<total_stock>8</total_stock>
<sap_idn_id/>
<sap_idn_item_id/>
<sap_po_id/>
<sap_po_item_id/>
<quantity>6</quantity>
<channel>CAJOO</channel>
</row>
<row>
<period_begin>2021-10-27 07:39:45.090462+00</period_begin>
<period_end/>
<line_id>7</line_id>
<reason>ORDER_PREPARED</reason>
<product_sku>pasquier-brioche-tressee-chocolat-630</product_sku>
<sap_ship_to_id/>
<sap_ship_from_id>par-sedaine</sap_ship_from_id>
<total_stock>8</total_stock>
<sap_idn_id/>
<sap_idn_item_id/>
<sap_po_id/>
<sap_po_item_id/>
<quantity>6</quantity>
<channel>CAJOO</channel>
</row>
</root>
Output <?xml version="1.0" encoding="UTF-8"?>
<root>
<row>
<period_begin>2021-10-27 07:39:45.090462+00</period_begin>
<period_end/>
<line_id>7</line_id>
<reason>ORDER_PREPARED</reason>
<product_sku>pasquier-brioche-tressee-chocolat-630</product_sku>
<sap_ship_to_id/>
<sap_ship_from_id>par-sedaine</sap_ship_from_id>
<total_stock>8</total_stock>
<sap_idn_id/>
<sap_idn_item_id/>
<sap_po_id/>
<sap_po_item_id/>
<quantity>6</quantity>
<channel>CAJOO</channel>
</row>
<row>
<period_begin>2021-10-27 07:39:45.090462+00</period_begin>
<period_end/>
<line_id>7</line_id>
<reason>ORDER_PREPARED</reason>
<product_sku>pasquier-brioche-tressee-chocolat-630</product_sku>
<sap_ship_to_id/>
<sap_ship_from_id>par-sedaine</sap_ship_from_id>
<total_stock>8</total_stock>
<sap_idn_id/>
<sap_idn_item_id/>
<sap_po_id/>
<sap_po_item_id/>
<quantity>6</quantity>
<channel>CAJOO</channel>
</row>
</root>
Hello Morten,
Thanks for your answer.
I would like to get all the "row" nodes with the child node "sap_ship_from_id" equals "ORDER_PREPARED". I can use the filter function into CPI but I will remove root tags so I need to put a "Content modifier" after just to add new root tags.
My idea is to do it into a groovy script below
- Get the body
- Appply the Xpath filter //root/row[reason='ORDER_PREPARED']
- get the new body then add root tags "<root> + body + "</root>",
<root>
<row>
<period_begin>2021-10-27 07:39:45.090462+00</period_begin>
<period_end/>
<line_id>6</line_id>
<reason>ORDERED_PREPARED</reason>
<product_sku>fromagers-halloumi</product_sku>
<sap_ship_to_id/>
<sap_ship_from_id>par-roty</sap_ship_from_id>
<total_stock>18</total_stock>
<sap_idn_id/>
<sap_idn_item_id/>
<sap_po_id/>
<sap_po_item_id/>
<quantity>2</quantity>
<channel>CAJOO</channel>
</row>
<row>
<period_begin>2021-10-27 07:39:45.090462+00</period_begin>
<period_end/>
<line_id>7</line_id>
<reason>DLC_LIMIT_DAYS_PASSED</reason>
<product_sku>pasquier-brioche-tressee-chocolat-630</product_sku>
<sap_ship_to_id/>
<sap_ship_from_id>par-sedaine</sap_ship_from_id>
<total_stock>8</total_stock>
<sap_idn_id/>
<sap_idn_item_id/>
<sap_po_id/>
<sap_po_item_id/>
<quantity>6</quantity>
<channel>CAJOO</channel>
</row>
</root>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.