Delete XML nodes in SQL server based on conditions - sql-server

I have xml that looks like
<MeasureSet>
<MeasureSetType val_type="name">Variant</MeasureSetType>
<Measure>
<MeasureType val_type="name">single nucleotide variant</MeasureType>
<AttributeSet>
<MeasureAttributeType val_type="name">HGVS</MeasureAttributeType>
<Attribute>NM_000054.4:c.838dupT</Attribute>
</AttributeSet>
<Citation>
<CitationType val_type="name">general</CitationType>
<ID Source="PubMed">10820168</ID>
</Citation>
<Citation>
<CitationType val_type="name">general</CitationType>
<ID Source="PubMed" />
</Citation>
<Citation>
<CitationType val_type="name">general</CitationType>
<ID Source="PubMed">9773787</ID>
</Citation>
<Citation>
<CitationType val_type="name">general</CitationType>
<ID Source="PubMed">18726898</ID>
</Citation>
<Citation>
<CitationType val_type="name">general</CitationType>
<ID Source="PubMed" />
</Citation>
</Measure>
</MeasureSet>
I want to delete the Citation element nodes that have Citation/ID/#Source = "PubMed" and Citation/ID is empty
This deletes only the ID element, but the correct ones
SET #myBlob.modify('delete //Citation/ID[#Source = ''PubMed''
and string-length(string(number(.))) = 0]')
and this deletes all Citation elements
SET #myBlob.modify('delete //Citation[ID/#Source = ''PubMed''
and string-length(string(number(.))) = 0]')
Seems there should be an easy solution I'm not hitting on. Any suggestions? Thanks

Your second one is checking the length of the wrong element - it's looking at (.), which is here the Citation element (because it's in a predicate on the Citation element). Use instead
SET #myBlob.modify('
delete //Citation[ID/#Source = ''PubMed''
and string-length(string(number(ID[1]))) = 0]')
where I have changed . to ID[1]. The [1] is needed because "'number()' requires a singleton (or empty sequence)".

Related

SQL Query XML with 'where' clause

I am trying to retrieve a single row of data based on an XML attribute.
The SQL I have so far is:
select C.query('.')
from Bookmarks
cross apply XMLValue.nodes('/rdBookmarks/Bookmark') as T(C)
The data returned from this query is (4 rows of data)
<Bookmark Report="DataExplorer" Name="DataExplorer" CustomColumn1="Analysis" CustomColumn2="Data Explorer" Description="Benefit Plan Count" SaveTime="2020-02-21T10:44:36-05:00" BookmarkID="79638e95-c5b7-43f1-b180-f5f31b50dea4" ExtraFile="Bookmarks_79638e95-c5b7-43f1-b180-f5f31b50dea4.xml">
<RequestParameters rdAgLoadSaved="Bookmarks_79638e95-c5b7-43f1-b180-f5f31b50dea4.xml" />
<SessionParameters />
</Bookmark>
<Bookmark Report="People.ContactInfo.EmergencyContactList" Name="" CustomColumn1="Report" CustomColumn2="Emergency Contact List" Description="Engineering Emergency Contacts" SaveTime="2020-02-21T11:48:28-05:00" BookmarkID="953e67ef-d45e-4fac-8d71-b2153a726612" FolderID="9ef9c6db-73d7-439e-b465-cc3c45d37397">
<RequestParameters inpMultiSelect_EmployeeStatus="" inpMultiSelect_Employer="" inpMultiSelect_OrgLevel1="22" inpMultiSelect_OrgLevel2="" inpMultiSelect_OrgLevel3="" inpMultiSelect_OrgLevel4="" inpMultiSelect_OrgLevel5="" inpMultiSelect_Manager="" inpMultiSelect_EmployeeType="" inpMultiSelect_SalariedHourly="" inpMultiSelect_ExemptStatus="" inpMultiSelect_JobTitle="" inpMultiSelect_State="" inpLastHireDate_Start="" inpLastHireDate_End="" inpEmpNo="" inpFirstName="" inpLastName="" inpCheckDate_Start="" inpCheckDate_End="" inpPeriodDate_Start="" inpPeriodDate_End="" inpMultiSelect_Category="" inpMultiSelect_EDTCode="" inpMultiSelect_Class1="" inpMultiSelect_Class2="" inpMultiSelect_Class3="" inpMultiSelect_Class4="" inpSelect_SelectionList="" inpMultiSelect_PostedStatus="" inpCheckBox_AllowBlankDates="" inpCheckBox_DefaultChecked_Manual="1" inpDate_SingleDate="" inpDate_Manual_SingleDate="" inpDateRange_Start="" inpDateRange_End="" inpDateRange2_Start="" inpDateRange2_End="" inpDateRange3_Start="" inpDateRange3_End="" inpDateRangeBlankDate_Start="" inpDateRangeBlankDate_End="" inpSelect_List="" inpMultiSelect_AnniversaryDateMonth="" inpMultiSelect_BenefitType="" inpMultiSelect_BenefitPlan="" inpMultiSelect_BirthDateMonth="" inpMultiSelect_BloodType="" inpMultiSelect_Event="" inpMultiSelect_EventLicenseCertif="" inpMultiSelect_NoteAuthor="" inpMultiSelect_NoteType="" inpMultiSelect_PastDue="" inpMultiSelect_PayFrequency="" inpMultiSelect_SalaryGrade="" inpMultiSelect_Skill="" inpMultiSelect_SourceData="" inpMultiSelect_SourceData2="" inpMultiSelect_UnionAffiliation="" inpMultiSelect_WaivedBenefit="" />
<SessionParameters />
</Bookmark>
<Bookmark Report="TotalRewards.Compensation.SalaryAnalysis" Name="" CustomColumn1="Analysis" CustomColumn2="Salary Analysis" Description="Annual Pay by Employee" SaveTime="2020-02-21T12:03:02-05:00" BookmarkID="30da52af-55d3-4c06-985a-12d428731773" ExtraFile="Bookmarks_30da52af-55d3-4c06-985a-12d428731773.xml">
<RequestParameters rdAgLoadSaved="Bookmarks_30da52af-55d3-4c06-985a-12d428731773.xml" />
<SessionParameters />
</Bookmark>
<Bookmark Report="Payroll.PayrollProcessing.PayrollAnalysis" Name="" CustomColumn1="Report" CustomColumn2="Payroll Analysis" Description="Payroll Age 40-49" FolderID="9ef9c6db-73d7-439e-b465-cc3c45d37397" SaveTime="2020-02-21T12:50:26-05:00" BookmarkID="2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe" ExtraFile="Bookmarks_2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe.xml">
<RequestParameters inpMultiSelect_EmployeeStatus="" inpMultiSelect_Employer="" inpMultiSelect_OrgLevel1="" inpMultiSelect_OrgLevel2="" inpMultiSelect_OrgLevel3="" inpMultiSelect_OrgLevel4="" inpMultiSelect_OrgLevel5="" inpMultiSelect_Manager="" inpMultiSelect_EmployeeType="" inpMultiSelect_SalariedHourly="" inpMultiSelect_ExemptStatus="" inpMultiSelect_JobTitle="" inpMultiSelect_State="" inpLastHireDate_Start="" inpLastHireDate_End="" inpEmpNo="" inpFirstName="" inpLastName="" inpCheckDate_Start="" inpCheckDate_End="" inpPeriodDate_Start="" inpPeriodDate_End="" inpMultiSelect_Category="" inpMultiSelect_EDTCode="" inpMultiSelect_Class1="" inpMultiSelect_Class2="" inpMultiSelect_Class3="" inpMultiSelect_Class4="" inpSelect_SelectionList="" inpMultiSelect_PostedStatus="" inpCheckBox_AllowBlankDates="" inpCheckBox_DefaultChecked_Manual="" inpDate_SingleDate="" inpDate_Manual_SingleDate="" inpDateRange_Start="" inpDateRange_End="" inpDateRange2_Start="" inpDateRange2_End="" inpDateRange3_Start="" inpDateRange3_End="" inpDateRangeBlankDate_Start="" inpDateRangeBlankDate_End="" inpSelect_List="" inpMultiSelect_AnniversaryDateMonth="" inpMultiSelect_BenefitType="" inpMultiSelect_BenefitPlan="" inpMultiSelect_BirthDateMonth="" inpMultiSelect_BloodType="" inpMultiSelect_Event="" inpMultiSelect_EventLicenseCertif="" inpMultiSelect_NoteAuthor="" inpMultiSelect_NoteType="" inpMultiSelect_PastDue="" inpMultiSelect_PayFrequency="" inpMultiSelect_SalaryGrade="" inpMultiSelect_Skill="" inpMultiSelect_SourceData="" inpMultiSelect_SourceData2="" inpMultiSelect_UnionAffiliation="" inpMultiSelect_WaivedBenefit="" rdAgLoadSaved="Bookmarks_2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe.xml" />
<SessionParameters />
</Bookmark>
but this returns each Bookmark element (4 total). I would like to add a where clause to only return one Bookmark node based on the BookmarkID, but can't seem to figure out how to do this. Is there a way to add something like
where C.query('#BookmarkID') = '953e67ef-d45e-4fac-8d71-b2153a726612'
so that only one Bookmark node is returned?
You could use the value() method to get a single value:
SELECT C.query('.'), BookmarkID = c.value('#BookmarkID', 'VARCHAR(36)')
FROM Bookmarks
CROSS APPLY XMLValue.nodes('/rdBookmarks/Bookmark') as T(C)
WHERE c.value('#BookmarkID', 'VARCHAR(36)') = '953e67ef-d45e-4fac-8d71-b2153a726612'
You can also filter directly in the nodes() method:
SELECT C.query('.'), BookmarkID = c.value('#BookmarkID', 'VARCHAR(36)')
FROM Bookmarks
CROSS APPLY XMLValue.nodes('/rdBookmarks/Bookmark[#BookmarkID="953e67ef-d45e-4fac-8d71-b2153a726612"]') as T(C);

Grabbing sublevel elements xml

I Have an XML conaining elemens as beeing an shipment and elements as beeein cargo-lines of that shipping.
In 1 file are multiple elements with 1 or more elements.
I need to create an XML file in another format.
Needed format:
<shipment>
--shipment lines
<cargo>
--cargo line
</cargo>
<cargo>
--cargo line
</cargo>
<cargo>
--cargo line
</cargo>
</shipment>
<shipment>
--shipment lines
<cargo>
--cargo line
</cargo>
</shipment>
Current SQL:
set #shipmentsXML = (SELECT
"customer_id" = T.c.query('./ediCustomerNumber').value('.', 'varchar(50)'),
"reference" = T.c.query('./ediReference').value('.', 'varchar(50)'),
(select
"unitamount" = T.C.query('./quantity').value('.', 'varchar(50)'),
"weight" = T.c.query('./grossWeight').value('.', 'varchar(50)'),
"loadingmeter" = T.c.query('./loadingMeters').value('.', 'varchar(50)')
FROM #Xml.nodes('./file/goodsLine') T(c)
FOR XML PATH ('cargo'), TYPE)
FROM #Xml.nodes('manifest-out/consol') T(c)
FOR XML PATH ('shipment')
)
working with the console tags, but no cargo line is showing
source XML:
<manifest-out type="tag">
<ediCustomerNumber>*******</ediCustomerNumber>
<ediCustomerDepartment>Ic</ediCustomerDepartment>
<transmitter>R</transmitter>
<receiver>*******</receiver>
<ediReference>*******</ediReference>
<referenceIndication>0</referenceIndication>
<internalShipmentNumber>*******</internalShipmentNumber>
<ediFunction1>6</ediFunction1>
<dateTimeZone>2019-07-24T13:05:55+02:00</dateTimeZone>
<fileHeader type="tag">
</fileHeader>
<consol type="tag">
<file type="tag">
<operationalPeriod>2019/07</operationalPeriod>
<loadingDate>2019-07-17</loadingDate>
<loadingTime>00:00:00</loadingTime>
<unloadingDate>2019-07-26</unloadingDate>
<unloadingTime>17:00:00</unloadingTime>
<primaryReference>8017883827</primaryReference>
<deliveryTerm>DAP</deliveryTerm>
<codeShedHandling>true</codeShedHandling>
<goodsLine type="tag">
<quantity>3.000</quantity>
<grossWeight>415.000</grossWeight>
<loadingMeters>1.633</loadingMeters>
</goodsLine>
<goodsLine type="tag">
<quantity>1.000</quantity>
<grossWeight>605.000</grossWeight>
<loadingMeters>4.633</loadingMeters>
</goodsLine>
<goodsLine type="tag">
<quantity>2.000</quantity>
<grossWeight>75.000</grossWeight>
<loadingMeters>2.633</loadingMeters>
</goodsLine>
</file>
</consol>
<consol type="tag">
<file type="tag">
<operationalPeriod>2019/07</operationalPeriod>
<loadingDate>2019-07-17</loadingDate>
<loadingTime>00:00:00</loadingTime>
<unloadingDate>2019-07-26</unloadingDate>
<unloadingTime>17:00:00</unloadingTime>
<primaryReference>8017883827</primaryReference>
<deliveryTerm>DAP</deliveryTerm>
<codeShedHandling>true</codeShedHandling>
<goodsLine type="tag">
<quantity>3.000</quantity>
<grossWeight>415.000</grossWeight>
<loadingMeters>1.633</loadingMeters>
</goodsLine>
</file>
</consol>
</manifest-out>
Could someone point me in the right direction on selecting the goodlines
Your question is missing the expected output, at least, it is not clear to me... But I hope I guessed this correctly:
SELECT #xml.value('(/manifest-out/ediCustomerNumber/text())[1]','varchar(50)') AS customer_id
,#xml.value('(/manifest-out/ediReference/text())[1]','varchar(50)') AS reference
,(
SELECT gl.value('(quantity/text())[1]','decimal(14,10)') AS unitamount
,gl.value('(grossWeight/text())[1]','decimal(14,10)') AS [weight]
,gl.value('(loadingMeters/text())[1]','decimal(14,10)') AS loadingmeter
FROM #xml.nodes('/manifest-out/consol/file/goodsLine') A(gl)
FOR XML PATH('cargo'),TYPE
)
FOR XML PATH('shipment');
The result
<shipment>
<customer_id>*******</customer_id>
<reference>*******</reference>
<cargo>
<unitamount>3.0000000000</unitamount>
<weight>415.0000000000</weight>
<loadingmeter>1.6330000000</loadingmeter>
</cargo>
<cargo>
<unitamount>1.0000000000</unitamount>
<weight>605.0000000000</weight>
<loadingmeter>4.6330000000</loadingmeter>
</cargo>
<cargo>
<unitamount>2.0000000000</unitamount>
<weight>75.0000000000</weight>
<loadingmeter>2.6330000000</loadingmeter>
</cargo>
</shipment>
The idea in short:
We can pick the 1:1 related values (your shipment data) directly from the XML and return it within <shipment>.
The nested SELECT will pick the repeating elements below <goodsLine> and return each of them within <cargo>.
Btw: Your own code was very, very close...
It would work if you either change your inner XPath to /manifest-out/consol/file/goodsLine or if you use T.c.nodes(). You are trying to use the relative path ./file/goodsLine against the source XML. You might even go the deep search route with FROM #xml.nodes('//goodsLine') T(c), but the general advise is: Be as specific as possible.
XQuery FLWOR expression is the best way to re-shape XML. There is no need to convert (1) XML data type into relational data, and after that (2) back to XML.
Check it out.
SQL
DECLARE #xml XML = '<manifest-out type="tag">
<ediCustomerNumber>*******</ediCustomerNumber>
<ediCustomerDepartment>Ic</ediCustomerDepartment>
<transmitter>R</transmitter>
<receiver>*******</receiver>
<ediReference>*******</ediReference>
<referenceIndication>0</referenceIndication>
<internalShipmentNumber>*******</internalShipmentNumber>
<ediFunction1>6</ediFunction1>
<dateTimeZone>2019-07-24T13:05:55+02:00</dateTimeZone>
<fileHeader type="tag">
</fileHeader>
<consol type="tag">
<file type="tag">
<operationalPeriod>2019/07</operationalPeriod>
<loadingDate>2019-07-17</loadingDate>
<loadingTime>00:00:00</loadingTime>
<unloadingDate>2019-07-26</unloadingDate>
<unloadingTime>17:00:00</unloadingTime>
<primaryReference>8017883827</primaryReference>
<deliveryTerm>DAP</deliveryTerm>
<codeShedHandling>true</codeShedHandling>
<goodsLine type="tag">
<quantity>3.000</quantity>
<grossWeight>415.000</grossWeight>
<loadingMeters>1.633</loadingMeters>
</goodsLine>
<goodsLine type="tag">
<quantity>1.000</quantity>
<grossWeight>605.000</grossWeight>
<loadingMeters>4.633</loadingMeters>
</goodsLine>
<goodsLine type="tag">
<quantity>2.000</quantity>
<grossWeight>75.000</grossWeight>
<loadingMeters>2.633</loadingMeters>
</goodsLine>
</file>
</consol>
</manifest-out>';
SELECT #xml.query('<shipment>
<customerID>{data(/manifest-out/ediCustomerNumber)}</customerID>
<CustomerDepartment>{data(/manifest-out/ediCustomerDepartment)}</CustomerDepartment>
{
for $x in /manifest-out/consol/file/goodsLine
return <cargo>
<unitamount>{data($x/quantity)}</unitamount>
<weight>{data($x/grossWeight)}</weight>
<loadingmeter>{data($x/loadingMeters)}</loadingmeter>
</cargo>
}
</shipment>');
Output XML:
<shipment>
<customerID>*******</customerID>
<CustomerDepartment>Ic</CustomerDepartment>
<cargo>
<unitamount>3.000</unitamount>
<weight>415.000</weight>
<loadingmeter>1.633</loadingmeter>
</cargo>
<cargo>
<unitamount>1.000</unitamount>
<weight>605.000</weight>
<loadingmeter>4.633</loadingmeter>
</cargo>
<cargo>
<unitamount>2.000</unitamount>
<weight>75.000</weight>
<loadingmeter>2.633</loadingmeter>
</cargo>
</shipment>
I found the solution:
SELECT g2.value('(/manifest-out/ediCustomerNumber/text())[1]','varchar(50)') AS customer_id
,g2.value('(/manifest-out/ediReference/text())[1]','varchar(50)') AS reference
,(
SELECT gl.value('(quantity/text())[1]','decimal(14,10)') AS unitamount
,gl.value('(grossWeight/text())[1]','decimal(14,10)') AS [weight]
,gl.value('(loadingMeters/text())[1]','decimal(14,10)') AS loadingmeter
FROM g2.nodes('./file/goodsLine') A(gl)
FOR XML PATH('cargo'),TYPE
)
FROM #xml.nodes('/manifest-out/consol') B(g2)
FOR XML PATH('shipment');
thnx for the help and suggestions, they help me finding the sollution!
As I already mentioned earlier there is no need (1) to convert XML data type into relational data, (2) CAST values into particular SQL Server data types, and after that (3) convert back to XML.
Here is an updated SQL with XQuery based on the refined requirements.
SELECT #xml.query('<root>
{
for $x in /manifest-out/consol
return <shipment>
<customerID>{data(/manifest-out/ediCustomerNumber)}</customerID>
<CustomerDepartment>{data(/manifest-out/ediCustomerDepartment)}</CustomerDepartment>
{
for $c in $x/file/goodsLine
return <cargo>
<unitamount>{data($c/quantity)}</unitamount>
<weight>{data($c/grossWeight)}</weight>
<loadingmeter>{data($c/loadingMeters)}</loadingmeter>
</cargo>
}
</shipment>
}
</root>');

XSL looping is not occurring properly at each level

I need to loop though this SAP IDOC to report shipment data. I need to break at each change of E2EDT37_KDMAT (part number), E2EDT37_VHILM_KU (package type) and E2EDT37_QUANTITY in the G07 node (PACKAGE). The current code seemed to work until there was more than one G16 (DELIVERY) node within a G01 (SHIPMENT) node.
This snippet of code doesn't produce XML output and the issue is seen in the message output.
I believe the method I am trying is just not valid and I will find another way. But I don't understand why exactly. I've tried preceding-sibling instead of preceding and just got different wrong output.
Each loop uses the same predicate as the last with one more criterion added to identify all matching the E2EDT37 records and perform the next statement once for each unique value of E2EDT37_KDMAT, E2EDT37_VHILM_KU and lastly E2EDT37_QUANTITY. It seems to come so close but never gets it right. What is my misunderstanding of the way E2EDT37_KDMAT[not(.=preceding::E2EDT37_KDMAT)] works here?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.1" xmlns:exsl="http://exslt.org/common"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:XmlTransform="java:de.axway.converter.xml.xsltextensions.XsltExtensions" exclude-result-prefixes="XmlTransform xsl exsl">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="/ACTIS">
<xsl:message></xsl:message>
<xsl:call-template name="DESADV_D96A"/>
</xsl:template>
<xsl:template name="DESADV_D96A">
<xsl:for-each select="//G16">
<xsl:variable name="current-delivery" select="E2EDL20/E2EDL20_VBELN "/>
<xsl:choose>
<xsl:when test="/ACTIS/G01/G07[#PACK_TYPE='OUTER']/E2EDT37[contains(E2EDT37_DELIVERIES, $current-delivery)]">
<xsl:call-template name="Create_Outer_PAC">
<xsl:with-param name="current-delivery" select=" $current-delivery "/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="Create_Outer_PAC">
<xsl:param name="current-delivery"/>
<xsl:message>In Create_Outer_PACK Delivery: <xsl:value-of select="$current-delivery"/></xsl:message>
<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='OUTER'][contains(E2EDT37_DELIVERIES, $current-delivery)]">
<xsl:variable name="Pallet" select="current()"/>
<xsl:message>For each Outer_PAC : <xsl:value-of select="$Pallet/E2EDT37_EXIDV"/></xsl:message>
<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery]/E2EDT37_KDMAT[not(.=preceding::E2EDT37_KDMAT)]">
<xsl:variable name="current-part" select="current()"/>
<xsl:message>For each E2EDT37_KDMAT : <xsl:value-of select="$current-part"/></xsl:message>
<xsl:message select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]/E2EDT37_VHILM_KU"/>
<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]/E2EDT37_VHILM_KU[not(.=preceding::E2EDT37_VHILM_KU)]">
<xsl:variable name="current-vhilm_ku" select="current()"/>
<xsl:message>For each E2EDT37_VHILM_KU: <xsl:value-of select="$current-vhilm_ku"/></xsl:message>
<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part][E2EDT37_VHILM_KU=$current-vhilm_ku]/E2EDT37_QUANTITY[not(.=preceding::E2EDT37_QUANTITY)]">
<xsl:variable name="current-packqty" select="current()"/>
<xsl:message></xsl:message>
<xsl:message>For each E2EDT37_QUANTITY: <xsl:value-of select="$current-packqty"/></xsl:message>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Data
<?xml version="1.0" encoding="UTF-8"?>
<ACTIS>
<EDI_DC>
<EDI_DC_TABNAM>EDI_DC40</EDI_DC_TABNAM>
<EDI_DC_CREDAT>20190702</EDI_DC_CREDAT>
<EDI_DC_CRETIM>210325</EDI_DC_CRETIM>
<EDI_DC_SERIAL>20190702210323</EDI_DC_SERIAL>
</EDI_DC>
<G01>
<E2EDT20>
<E2EDT20_SEGNAM>E2EDT20002</E2EDT20_SEGNAM>
<E2EDT20_MANDT>100</E2EDT20_MANDT>
<E2EDT20_DOCNUM>0000004250699555</E2EDT20_DOCNUM>
<E2EDT20_SEGNUM>000001</E2EDT20_SEGNUM>
<E2EDT20_PSGNUM>000000</E2EDT20_PSGNUM>
<E2EDT20_HLEVEL>01</E2EDT20_HLEVEL>
<E2EDT20_TKNUM>0049409223</E2EDT20_TKNUM>
</E2EDT20>
<G07 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
<E2EDT37 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
<E2EDT37_SEGNAM>E2EDT37006</E2EDT37_SEGNAM>
<E2EDT37_MANDT>100</E2EDT37_MANDT>
<E2EDT37_DOCNUM>0000004250699555</E2EDT37_DOCNUM>
<E2EDT37_SEGNUM>000044</E2EDT37_SEGNUM>
<E2EDT37_PSGNUM>000001</E2EDT37_PSGNUM>
<E2EDT37_HLEVEL>02</E2EDT37_HLEVEL>
<E2EDT37_EXIDV>00000000000505755236</E2EDT37_EXIDV>
<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
<E2EDT37_PACK_TYPE>INNER</E2EDT37_PACK_TYPE>
<E2EDT37_CHILDREN>0</E2EDT37_CHILDREN>
<E2EDT37_PARENT>505059227</E2EDT37_PARENT>
<E2EDT37_DELIVERY>0037371519</E2EDT37_DELIVERY>
<E2EDT37_DELIVERY_POSITION>000010</E2EDT37_DELIVERY_POSITION>
<E2EDT37_QUANTITY>8500.000</E2EDT37_QUANTITY>
<E2EDT37_UOM>PCE</E2EDT37_UOM>
<E2EDT37_KDMAT>6561111</E2EDT37_KDMAT>
<E2EDT37_VBRST>1000</E2EDT37_VBRST>
</E2EDT37>
</G07>
<G07 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
<E2EDT37 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
<E2EDT37_SEGNAM>E2EDT37006</E2EDT37_SEGNAM>
<E2EDT37_MANDT>100</E2EDT37_MANDT>
<E2EDT37_DOCNUM>0000004250699555</E2EDT37_DOCNUM>
<E2EDT37_SEGNUM>000047</E2EDT37_SEGNUM>
<E2EDT37_PSGNUM>000001</E2EDT37_PSGNUM>
<E2EDT37_HLEVEL>02</E2EDT37_HLEVEL>
<E2EDT37_EXIDV>00000000000505755237</E2EDT37_EXIDV>
<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
<E2EDT37_PACK_TYPE>INNER</E2EDT37_PACK_TYPE>
<E2EDT37_CHILDREN>0</E2EDT37_CHILDREN>
<E2EDT37_PARENT>505059227</E2EDT37_PARENT>
<E2EDT37_DELIVERY>0037371484</E2EDT37_DELIVERY>
<E2EDT37_DELIVERY_POSITION>000010</E2EDT37_DELIVERY_POSITION>
<E2EDT37_QUANTITY>7000.000</E2EDT37_QUANTITY>
<E2EDT37_UOM>PCE</E2EDT37_UOM>
<E2EDT37_KDMAT>6561143</E2EDT37_KDMAT>
<E2EDT37_VBRST>1000</E2EDT37_VBRST>
</E2EDT37>
</G07>
<G07 PACK_TYPE="OUTER" CHILDREN="2" MIXED="1">
<E2EDT37 PACK_TYPE="OUTER" CHILDREN="2" MIXED="1">
<E2EDT37_SEGNAM>E2EDT37006</E2EDT37_SEGNAM>
<E2EDT37_MANDT>100</E2EDT37_MANDT>
<E2EDT37_DOCNUM>0000004250699555</E2EDT37_DOCNUM>
<E2EDT37_SEGNUM>000050</E2EDT37_SEGNUM>
<E2EDT37_PSGNUM>000001</E2EDT37_PSGNUM>
<E2EDT37_HLEVEL>02</E2EDT37_HLEVEL>
<E2EDT37_EXIDV>505059227</E2EDT37_EXIDV>
<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
<E2EDT37_CHILDREN>2</E2EDT37_CHILDREN>
<E2EDT37_CONTENTS>00000000000505755236:00000000000505755237:</E2EDT37_CONTENTS>
<E2EDT37_PACK_TYPE>OUTER</E2EDT37_PACK_TYPE>
<E2EDT37_DELIVERIES>0037371519 0037371484</E2EDT37_DELIVERIES>
</E2EDT37>
</G07>
<G16>
<E2EDL20>
<E2EDL20_SEGNAM>E2EDL20004</E2EDL20_SEGNAM>
<E2EDL20_MANDT>100</E2EDL20_MANDT>
<E2EDL20_DOCNUM>0000004250699555</E2EDL20_DOCNUM>
<E2EDL20_SEGNUM>000077</E2EDL20_SEGNUM>
<E2EDL20_PSGNUM>000001</E2EDL20_PSGNUM>
<E2EDL20_HLEVEL>02</E2EDL20_HLEVEL>
<E2EDL20_VBELN>0037371484</E2EDL20_VBELN>
<E2EDL20_VSTEL>0016</E2EDL20_VSTEL>
<E2EDL20_VKORG>0060</E2EDL20_VKORG>
<E2EDL20_VKBUR>EUR</E2EDL20_VKBUR>
<E2EDL20_LGNUM>D16</E2EDL20_LGNUM>
<E2EDL20_ABLAD>JAG01</E2EDL20_ABLAD>
<E2EDL20_INCO1>FCA</E2EDL20_INCO1>
<E2EDL20_INCO2>NÜRNBERG</E2EDL20_INCO2>
<E2EDL20_ROUTE>DES129</E2EDL20_ROUTE>
<E2EDL20_VSBED>ST</E2EDL20_VSBED>
<E2EDL20_BTGEW>107.000</E2EDL20_BTGEW>
<E2EDL20_NTGEW>107.000</E2EDL20_NTGEW>
<E2EDL20_GEWEI>KGM</E2EDL20_GEWEI>
<E2EDL20_VOLUM>1036.427</E2EDL20_VOLUM>
<E2EDL20_VOLEH>DMQ</E2EDL20_VOLEH>
<E2EDL20_ANZPK>00000</E2EDL20_ANZPK>
<E2EDL20_PARID>UNKNOWN</E2EDL20_PARID>
<E2EDL20_PODAT>20190702</E2EDL20_PODAT>
<E2EDL20_POTIM>210324</E2EDL20_POTIM>
</E2EDL20>
<G29>
<E2EDL24>
<E2EDL24_POSNR>000010</E2EDL24_POSNR>
<E2EDL24_KDMAT>6561143</E2EDL24_KDMAT>
<E2EDL24_LFIMG>7000.000</E2EDL24_LFIMG>
<E2EDL24_VRKME>PCE</E2EDL24_VRKME>
<E2EDL24_VBRST>1000</E2EDL24_VBRST>
<E2EDL24_KDMAT35>6561143</E2EDL24_KDMAT35>
<E2EDL24_POSEX>000000</E2EDL24_POSEX>
<E2EDL24_DELIVERY>0037371484</E2EDL24_DELIVERY>
<E2EDL24_PO>5500229851</E2EDL24_PO>
<E2EDL24_PO_DATE>20150612</E2EDL24_PO_DATE>
</E2EDL24>
</G29>
<G29>
<E2EDL24>
<E2EDL24_POSNR>900001</E2EDL24_POSNR>
<E2EDL24_KDMAT>0000SON</E2EDL24_KDMAT>
<E2EDL24_LFIMG>1.000</E2EDL24_LFIMG>
<E2EDL24_VRKME>PCE</E2EDL24_VRKME>
<E2EDL24_VBRST>1000</E2EDL24_VBRST>
<E2EDL24_KDMAT35>0000SON</E2EDL24_KDMAT35>
<E2EDL24_POSEX>000000</E2EDL24_POSEX>
<E2EDL24_DELIVERY>0037371484</E2EDL24_DELIVERY>
</E2EDL24>
</G29>
</G16>
<G16>
<E2EDL20>
<E2EDL20_SEGNAM>E2EDL20004</E2EDL20_SEGNAM>
<E2EDL20_MANDT>100</E2EDL20_MANDT>
<E2EDL20_DOCNUM>0000004250699555</E2EDL20_DOCNUM>
<E2EDL20_SEGNUM>000170</E2EDL20_SEGNUM>
<E2EDL20_PSGNUM>000001</E2EDL20_PSGNUM>
<E2EDL20_HLEVEL>02</E2EDL20_HLEVEL>
<E2EDL20_VBELN>0037371519</E2EDL20_VBELN>
<E2EDL20_VSTEL>0016</E2EDL20_VSTEL>
<E2EDL20_VKORG>0060</E2EDL20_VKORG>
<E2EDL20_VKBUR>EUR</E2EDL20_VKBUR>
<E2EDL20_LGNUM>D16</E2EDL20_LGNUM>
<E2EDL20_ABLAD>JAG01</E2EDL20_ABLAD>
<E2EDL20_INCO1>FCA</E2EDL20_INCO1>
<E2EDL20_INCO2>NÜRNBERG</E2EDL20_INCO2>
<E2EDL20_ROUTE>DES129</E2EDL20_ROUTE>
<E2EDL20_VSBED>ST</E2EDL20_VSBED>
<E2EDL20_BTGEW>140.600</E2EDL20_BTGEW>
<E2EDL20_NTGEW>127.500</E2EDL20_NTGEW>
<E2EDL20_GEWEI>KGM</E2EDL20_GEWEI>
<E2EDL20_VOLUM>42840.000</E2EDL20_VOLUM>
<E2EDL20_VOLEH>CMQ</E2EDL20_VOLEH>
<E2EDL20_ANZPK>00000</E2EDL20_ANZPK>
<E2EDL20_PARID>UNKNOWN</E2EDL20_PARID>
<E2EDL20_PODAT>20190702</E2EDL20_PODAT>
<E2EDL20_POTIM>210325</E2EDL20_POTIM>
</E2EDL20>
<G29>
<E2EDL24>
<E2EDL24_POSNR>000010</E2EDL24_POSNR>
<E2EDL24_KDMAT>6561111</E2EDL24_KDMAT>
<E2EDL24_LFIMG>8500.000</E2EDL24_LFIMG>
<E2EDL24_VRKME>PCE</E2EDL24_VRKME>
<E2EDL24_VBRST>1000</E2EDL24_VBRST>
<E2EDL24_KDMAT35>6561111</E2EDL24_KDMAT35>
<E2EDL24_POSEX>000000</E2EDL24_POSEX>
<E2EDL24_DELIVERY>0037371519</E2EDL24_DELIVERY>
<E2EDL24_PO>5500229848</E2EDL24_PO>
<E2EDL24_PO_DATE>20150612</E2EDL24_PO_DATE>
</E2EDL24>
</G29>
</G16>
</G01>
</ACTIS>
Resulting Output
1) In Create_Outer_PAC Delivery : 0037371484
2) For each Outer_PAC : 505059227
3) For each E2EDT37_KDMAT : 6561143 Good break here at unique KDMAT
I find and display a single matching VHILM_KU here but the next line that tries to loop at each VHILM_KU doesn't occur with the same Xpath as the xsl:message
<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]/E2EDT37_VHILM_KU[not(.=preceding::E2EDT37_VHILM_KU)]">
<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
No For each E2EDT37_VHILM_KU break on E2EDT37_VHILM_KU=0000SON
1) In Create_Outer_PAC Delivery : 0037371519
2) For each Outer_PAC : 505059227
3) For each E2EDT37_KDMAT : 6561111
<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
This one breaks as expected. You see we have an E2EDT37_VHILM_KU found with value 0000SON in the line above here.
I don't reach this message in the first for-each loop above although we also find and display the same E2EDT37_VHILM_KU of 0000SON.
We have two E2EDT37 segments with KDMAT values of 6561143 and 6561141. The first loop breaks at each unique KDMAT as expected.
4) For each E2EDT37_VHILM_KU : 0000SON
5) For each E2EDT37_QUANTITY : 8500.000
Is it valid to check for unique values with /E2EDT37_VHILM_KU[not(.=preceding::E2EDT37_VHILM_KU)] at the same time as limiting the resulting nodes with the predicates [E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]? I assume that's where I am wrong but the paradigm is not clear to me. The message output shows me the Xpath did find a single VHILM_KU. The next for-each statement with the same Xpath finds nothing.
Is that clearer or more confusing?

Need to remove some properties from Junit xml report generated through SOAPUI (open source)

While running my API test via jenkins(linux machine), its generating Junit report xml with some invalid character in properties tags.
<property name="LESS_TERMCAP_us" value="[04;38;5;111m"/>
Due to which jenkins throws error for invalid xml.
How can I remove properties from the generated xml.
Thanks in advance.
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="Sanity" tests="3" failures="3" errors="0" time="5.354">
<properties><property name="JOB_NAME" value="QA-API-Automation-Sanity"/>
<property name="java.vendor" value="Oracle Corporation"/><property name="PWD" value="/var/lib/jenkins"/><property name="sun.java.launcher" value="SUN_STANDARD"/><property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/><property name="PATH" value="/var/lib/jenkins/tools/chromedriver:/usr/local/bin:/bin:/usr/bin:/opt/aws/bin:/usr/lib/apache-maven-3.3.9/bin/"/><property name="JENKINS_HOME" value="/var/lib/jenkins"/><property name="AWS_SDK_LOAD_CONFIG" value="true"/><property name="HUDSON_SERVER_COOKIE" value="2567307d622fab24"/><property name="POM_ARTIFACTID" value="apitest"/><property name="os.name" value="Linux"/><property name="EXECUTOR_NUMBER" value="3"/><property name="sun.boot.class.path" value="/usr/java/jdk1.8.0_60/jre/lib/resources.jar:/usr/java/jdk1.8.0_60/jre/lib/rt.jar:/usr/java/jdk1.8.0_60/jre/lib/sunrsasign.jar:/usr/java/jdk1.8.0_60/jre/lib/jsse.jar:/usr/java/jdk1.8.0_60/jre/lib/jce.jar:/usr/java/jdk1.8.0_60/jre/lib/charsets.jar:/usr/java/jdk1.8.0_60/jre/lib/jfr.jar:/usr/java/jdk1.8.0_60/jre/classes"/><property name="POM_DISPLAYNAME" value="APITest"/><property name="java.vm.specification.vendor" value="Oracle Corporation"/><property name="ROOT_BUILD_CAUSE" value="MANUALTRIGGER"/><property name="NODE_LABELS" value="QA-Slave qa-slave"/><property name="java.runtime.version" value="1.8.0_60-b27"/><property name="user.name" value="jenkins"/><property name="SSH_CONNECTION" value="52.14.5.155 42186 10.0.0.142 22"/><property name="guice.disable.misplaced.annotation.check" value="true"/><property name="SSH_CLIENT" value="52.14.5.155 42186 22"/><property name="PYTHON_INSTALL_LAYOUT" value="amzn"/><property name="user.language" value="en"/><property name="RUN_CHANGES_DISPLAY_URL" value="https://jenkins.gl-poc.com/job/QA-API-Automation-Sanity/22/display/redirect?page=changes"/><property name="JOB_BASE_NAME" value="QA-API-Automation-Sanity"/><property name="BUILD_DISPLAY_NAME" value="#22"/><property name="sun.boot.library.path" value="/usr/java/jdk1.8.0_60/jre/lib/amd64"/><property name="AWS_AUTO_SCALING_HOME" value="/opt/aws/apitools/as"/><property name="java.version" value="1.8.0_60"/><property name="user.timezone" value="Etc/UTC"/><property name="sun.arch.data.model" value="64"/><property name="NODE_NAME" value="QA-Slave"/><property name="NLSPATH" value="/usr/dt/lib/nls/msg/%L/%N.cat"/><property name="java.endorsed.dirs" value="/usr/java/jdk1.8.0_60/jre/lib/endorsed"/><property name="BUILD_ID" value="22"/><property name="sun.cpu.isalist" value=""/><property name="sun.jnu.encoding" value="UTF-8"/><property name="file.encoding.pkg" value="sun.io"/><property name="SHELL" value="/bin/bash"/><property name="file.separator" value="/"/><property name="java.specification.name" value="Java Platform API Specification"/>
<property name="LESS_TERMCAP_us" value="[04;38;5;111m"/>
<property name="java.class.version" value="52.0"/><property name="org.slf4j.simpleLogger.defaultLogLevel" value="info"/><property name="user.country" value="US"/><property name="securerandom.source" value="file:/dev/./urandom"/><property name="java.home" value="/usr/java/jdk1.8.0_60/jre"/><property name="java.vm.info" value="mixed mode"/><property name="LESSOPEN" value="||/usr/bin/lesspipe.sh %s"/><property name="os.version" value="4.4.41-36.55.amzn1.x86_64"/><property name="EC2_AMITOOL_HOME" value="/opt/aws/amitools/ec2"/><property name="RUN_DISPLAY_URL" value="https://jenkins.gl-poc.com/job/QA-API-Automation-Sanity/22/display/redirect"/>
<property name="LESS_TERMCAP_ue" value="[0m"/><property name="POM_VERSION" value="1.0-SNAPSHOT"/><property name="sun.font.fontmanager" value="sun.awt.X11FontManager"/><property name="path.separator" value=":"/><property name="java.vm.version" value="25.60-b23"/><property name="GIT_PREVIOUS_COMMIT" value="c20674b0f57ce7beb1a881f19bdfeae2a5b602e7"/><property name="JOB_DISPLAY_URL" value="https://jenkins.gl-poc.com/job/QA-API-Automation-Sanity/display/redirect"/><property name="SHLVL" value="1"/><property name="_" value="/usr/bin/java"/><property name="java.awt.printerjob" value="sun.print.PSPrinterJob"/><property name="JAVA_HOME" value="/usr/java/jdk1.8.0_60"/><property name="sun.io.unicode.encoding" value="UnicodeLittle"/><property name="awt.toolkit" value="sun.awt.X11.XToolkit"/><property name="LOGNAME" value="jenkins"/><property name="POM_PACKAGING" value="jar"/><property name="HOME" value="/home/jenkins"/><property name="POM_GROUPID" value="com.api"/><property name="user.home" value="/home/jenkins"/><property name="JENKINS_SERVER_COOKIE" value="2567307d622fab24"/><property name="BUILD_TAG" value="jenkins-QA-API-Automation-Sanity-22"/><property name="HUDSON_URL" value="https://jenkins.gl-poc.com/"/><property name="java.specification.vendor" value="Oracle Corporation"/><property name="CLASSPATH" value=""/><property name="java.library.path" value="/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib"/><property name="java.vendor.url" value="http://java.oracle.com/"/><property name="ROOT_BUILD_CAUSE_MANUALTRIGGER" value="true"/><property name="java.vm.vendor" value="Oracle Corporation"/><property name="maven.home" value="/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven3.3.9"/><property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/><property name="sun.java.command" value="jenkins.maven3.agent.Maven33Main /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven3.3.9 /var/lib/jenkins/slave.jar /var/lib/jenkins/maven33-interceptor.jar /var/lib/jenkins/maven3-interceptor-commons.jar 44390"/><property name="java.class.path" value="/var/lib/jenkins/maven33-agent.jar:/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven3.3.9/boot/plexus-classworlds-2.5.2.jar:/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven3.3.9/conf/logging"/><property name="EC2_HOME" value="/opt/aws/apitools/ec2"/><property name="java.vm.specification.name" value="Java Virtual Machine Specification"/><property name="java.vm.specification.version" value="1.8"/><property name="MAIL" value="/var/mail/jenkins"/><property name="M2_HOME" value="/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven3.3.9"/>
<property name="LESS_TERMCAP_me" value="[0m"/><property name="sun.cpu.endian" value="little"/><property name="sun.os.patch.level" value="unknown"/>
<property name="LESS_TERMCAP_md" value="[01;38;5;208m"/>
<property name="LESS_TERMCAP_mb" value="[01;31m"/>
<property name="java.io.tmpdir" value="/tmp"/><property name="PATH+MAVEN" value="/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven3.3.9/bin"/><property name="HUDSON_HOME" value="/var/lib/jenkins"/>
<property name="LESS_TERMCAP_se" value="[0m"/><property name="OLDPWD" value="/home/jenkins"/>
<property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/>
<property name="BUILD_URL" value="https://jenkins.gl-poc.com/job/QA-API-Automation-Sanity/22/"/>
<property name="os.arch" value="amd64"/><property name="java.awt.graphicsenv" value="sun.awt.X11GraphicsEnvironment"/><property name="java.ext.dirs" value="/usr/java/jdk1.8.0_60/jre/lib/ext:/usr/java/packages/lib/ext"/><property name="JOB_URL" value="https://jenkins.gl-poc.com/job/QA-API-Automation-Sanity/"/><property name="_JAVA_OPTIONS" value="-Xmx2048m"/><property name="user.dir" value="/var/lib/jenkins/workspace/QA-API-Automation-Sanity"/><property name="MAVEN_HOME" value="/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven3.3.9"/><property name="line.separator" value="
"/>
<property name="BUILD_NUMBER" value="22"/><property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/><property name="JENKINS_URL" value="https://jenkins.gl-poc.com/"/>
<property name="GIT_BRANCH" value="origin/develop"/><property name="PATH+CHROMEDRIVER" value="/var/lib/jenkins/tools/chromedriver"/><property name="BUILD_CAUSE_MANUALTRIGGER" value="true"/><property name="GIT_COMMIT" value="ad5e9221a4f489a8a60e60bed86061be514bccda"/><property name="LANG" value="en_US.UTF-8"/><property name="file.encoding" value="UTF-8"/><property name="maven3.interceptor" value="/var/lib/jenkins/maven33-interceptor.jar"/><property name="WORKSPACE" value="/var/lib/jenkins/workspace/QA-API-Automation-Sanity"/><property name="maven3.interceptor.common" value="/var/lib/jenkins/maven3-interceptor-commons.jar"/><property name="AWS_PATH" value="/opt/aws"/><property name="AWS_ELB_HOME" value="/opt/aws/apitools/elb"/><property name="AWS_CLOUDWATCH_HOME" value="/opt/aws/apitools/mon"/><property name="java.specification.version" value="1.8"/><property name="BUILD_CAUSE" value="MANUALTRIGGER"/><property name="USER" value="jenkins"/><property name="XFILESEARCHPATH" value="/usr/dt/app-defaults/%L/Dt"/><property name="GIT_URL" value="ssh://git#bitbucket.pearson.com/glpnfr/glp-api-automation-qa.git"/></properties>
<testcase name="Login" time="1.595">
<failure type="Failing due to failed test step" message="Failing due to failed test step">
<![CDATA[<h3><b>claimTokenIdTransfer Failed</b></h3><pre>Error performing transfer [claimTokenRetrieval] - Missing target property
</pre><hr/><h3><b>retrievalClaim Failed</b></h3><pre>[Valid HTTP Status Codes] Response status code:401 is not in acceptable list of status codes
</pre><hr/>]]>
</failure>
</testcase>
</testsuite>
Here you go, comments in-line:
Pass the xml as string to parseText method.
//Pass xml string
def pxml = new XmlSlurper().parseText(xml)
//Get the suites
def suites = pxml.'**'.findAll{ it.name() == 'testsuite' }
//Remove properties node
suites.each{ it.properties.replaceNode {} }
//This gives the new xml without properties element
def output = groovy.xml.XmlUtil.serialize(pxml)​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
//Below would unescape the xml
def map = ['<' : '<', '>' : '>', '"' : '"', '&apos;':'\'', '&':'&']
map.collect {k,v -> output = output.replaceAll(k,v)}
println output​
You can quickly try this online Demo

XML XPath - Sub path

Using the following XML, in SQL Server how can I get a table of LineItemId,PetId(value),vetid(Value)? I'm stumped.
Basically, It should return:
255fa32c-dce6-4e7a-83a5-4b45f22f00fc 75866 12916
183dc279-53a6-45fc-9e75-57770582b6bc 34535 34546
From this XML:
<PurchaseOrder>
<OrderForms>
<OrderForm>
<LineItems>
<LineItem LineItemId="255fa32c-dce6-4e7a-83a5-4b45f22f00fc">
<WeaklyTypedProperties>
<WeaklyTypedProperty Name="petId" Value="75866" Type="String" />
<WeaklyTypedProperty Name="vetId" Value="12916" Type="String" />
</WeaklyTypedProperties>
</LineItem>
<LineItem LineItemId="183dc279-53a6-45fc-9e75-57770582b6bc">
<WeaklyTypedProperties>
<WeaklyTypedProperty Name="petId" Value="345345" Type="String" />
<WeaklyTypedProperty Name="vetId" Value="345346" Type="String" />
</WeaklyTypedProperties>
</LineItem>
</LineItems>
</OrderForm>
</OrderForms>
</PurchaseOrder>
I should state I have tried the following, but it gives blanks for petId and vetId:
SELECT
p.value('#LineItemId','NVARCHAR(100)')
,p.query('//PurchaseOrder/OrderForms/OrderForm[1]/LineItems/LineItem[1]/WeaklyTypedProperties/WeaklyTypedProperty[Name="petId"]')
,p.query('//PurchaseOrder/OrderForms/OrderForm[1]/LineItems/LineItem[1]/WeaklyTypedProperties/WeaklyTypedProperty[Name="vetid"]')
FROM
dbo.[PurchaseOrdersMarshalledData] pomd
CROSS APPLY pomd.[MarshalledData].nodes('//PurchaseOrder/OrderForms/OrderForm[1]/LineItems/LineItem') x(p)
Thanks!
SELECT
[LineItemId] = l.value('#LineItemId', 'nvarchar(100)'),
[PetId] = w.value('WeaklyTypedProperty[#Name="petId"][1]/#Value', 'int'),
[VetId] = w.value('WeaklyTypedProperty[#Name="vetId"][1]/#Value', 'int')
FROM dbo.[PurchaseOrdersMarshalledData] pomp
CROSS APPLY pomp.[MarshalledData].nodes('//PurchaseOrder/OrderForms/OrderForm[1]/LineItems/LineItem') LineItem(l)
CROSS APPLY l.nodes('WeaklyTypedProperties') WeaklyTypedProperty(w)
Haven't tried it... maybe the syntaxis is not 100% correct...
<xsl:for-each select="/PurcharseOrder/OrderForms/OrderForm/LineItems/LineItem"/>
<xsl:value-of select="#LineItemId"/>
<xsl:for-each select="WeaklyTypedProperties"/>
<xsl:value-of select="WeaklyTypedProperty/#Value"/>
</xsl:for-each>
</xsl:for-each>

Resources