The selection of elements from XML using XSTL - xslt-3.0

Please, help me with this strong task.
I have:
<Animals>
<Animal Price="68 USD">
<Name>Dobby</Name>
<Address>
<AddressFull>Ukraine Nikolaev Ivanko 148</AddressFull>
<City>Nikolaev</City>
<Country>Ukraine</Country>
</Address>
</Animal>
<Animal Price="50 BYN">
<Name>Garry</Name>
<Address>
<AddressFull>Belarus Minsk Sovenskaya 198</AddressFull>
<City>Minsk</City>
<Country>RB</Country>
</Address>
</Animal>
<Animal Price="10 USD">
<Name>Luky</Name>
<Address>
<AddressFull>Bulgary Sofia Pushkina 45</AddressFull>
<City>Sofia</City>
<Country>Bulgary</Country>
</Address>
</Animal>
<Animal Price="30 USD">
<Name>Mike</Name>
<Address>
<AddressFull>Ukraine Nikolaev Shevchenko 90</AddressFull>
<City>Nikolaev</City>
<Country>Ukraine</Country>
</Address>
</Animal>
</Animals>
I need animals in the table only from the city of Nikolaev in this order like that:
<Lists>
<Names>
<Name>Dobby</Name>
<Name>Mike</Name>
</Names>
<Prices>
<Price>68 USD</Price>
<Price>30 USD</Price>
</Prices>
<Addresses>
<Address>Ukraine Nikolaev Ivanko 148</Address>
<Address>Ukraine Nikolaev Shevchenko 90</Address>
</Addresses>
</Lists>
Please help me to compose the XSLT file. My file XSLT outputs all animals((

Related

Extract data from an XML string with xml.etree.ElementTree

I have an XML string and I need to extract the first three "col" tag in each group of "row". In other words, the output should be the following:
['1043100330', 'Smith', 'John', '1043100331', 'Swartz', 'Francis', '1043100332', 'Laff', 'Michael']
This is the XML:
data = '''<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<processOXIMessageResponse xmlns="urn:com:singun:webservice" xmlns:ns="urn:com:singun:webservice">
<ns1:processOXIMessageReturn xmlns:ns1="urn:com:singun:webservice">
<SingunDocument xmlns="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" protocol="OXI">
<sessionId xmlns="">1613762599483</sessionId>
<command xmlns="" echo="" xsi:type="ServiceProviderGetListResponse">
<serviceProviderTable>
<colHeading>User Id</colHeading>
<colHeading>Last Name</colHeading>
<colHeading>First Name</colHeading>
<colHeading>Email Address</colHeading>
<colHeading>Phone Number</colHeading>
<colHeading>Extension</colHeading>
<colHeading>Country Code</colHeading>
<colHeading>National Prefix</colHeading>
<row>
<col>1043100330</col>
<col>Smith</col>
<col>John</col>
<col>jsmith#example.com</col>
<col>1043101330</col>
<col>1330</col>
<col>52</col>
<col>52</col>
</row>
<row>
<col>1043100331</col>
<col>Swartz</col>
<col>Francis</col>
<col>fswartz#example.com</col>
<col>1043101331</col>
<col>1331</col>
<col>52</col>
<col>52</col>
</row>
<row>
<row>
<col>1043100332</col>
<col>Laff</col>
<col>Michael</col>
<col>mlaff#example.com</col>
<col>1043101332</col>
<col>1332</col>
<col>52</col>
<col>52</col>
</row>
</serviceProviderTable>
</command>
</SingunDocument>
</ns1:processOXIMessageReturn>
</processOXIMessageResponse>
</soapenv:Body>
</soapenv:Envelope>
The following is my code, but it extracts only the first "col" tag instead of the first three of each group as I would like:
import xml.etree.ElementTree as ET
users = []
root = ET.fromstring(resp)
for col in root.iterfind('.//row/col[1]'):
users.append(col.text)
print(users)
This is the output of my code:
['1043100330', '1043100331', '1043100332']
Please if you can give me a hand. Thanks a lot
You need to take into account the namespaces, as well as the structure of your xml. Try something like:
data = root.findall('.//{C}serviceProviderTable//{C}row')
for datum in data:
entries = datum.findall('.//{C}col')
users.append([entry.text.strip() for entry in entries[:3]])
for user in users:
print(user)
Output:
['1043100330', 'Smith', 'John']
['1043100331', 'Swartz', 'Francis']
['1043100332', 'Laff', 'Michael']

move an element to another element or create a new one if it does not exist using xslt-3

using xslt 3, i need to take all content elements' values, and move them to the title elements (if the title elements already exist in a record, they need to be appended with a separator like -) i now have inputted my real data, since the below solution does not solve the problem when implemented to something like:
example input:
<data>
<RECORD ID="31365">
<no>25099</no>
<seq>0</seq>
<date>2/4/2012</date>
<ver>2/4/2012</ver>
<access>021999</access>
<col>GS</col>
<call>889</call>
<pr>0</pr>
<days>0</days>
<stat>0</stat>
<ch>0</ch>
<title>1 title</title>
<content>1 content</content>
<sj>1956</sj>
</RECORD>
<RECORD ID="31366">
<no>25100</no>
<seq>0</seq>
<date>2/4/2012</date>
<ver>2/4/2012</ver>
<access>022004</access>
<col>GS</col>
<call>8764</call>
<pr>0</pr>
<days>0</days>
<stat>0</stat>
<ch>0</ch>
<sj>1956</sj>
<content>1 title</content>
</RECORD>
</data>
expected output:
<data>
<RECORD ID="31365">
<no>25099</no>
<seq>0</seq>
<date>2/4/2012</date>
<ver>2/4/2012</ver>
<access>021999</access>
<col>GS</col>
<call>889</call>
<pr>0</pr>
<days>0</days>
<stat>0</stat>
<ch>0</ch>
<title>1 title - 1 content</title>
<sj>1956</sj>
</RECORD>
<RECORD ID="31366">
<no>25100</no>
<seq>0</seq>
<date>2/4/2012</date>
<ver>2/4/2012</ver>
<access>022004</access>
<col>ΓΣ</col>
<call>8764</call>
<pr>0</pr>
<days>0</days>
<stat>0</stat>
<ch>0</ch>
<sj>1956</sj>
<title>1 title</title>
</RECORD>
<data>
with my attempt, i did not manage to move the elements, i just got an empty line where the content element existed, so please add the removal of blank lines in the suggested solution.
i believe the removal of blank lines could be fixed with the use of
<xsl:template match="text()"/>
One way to achieve this is the following template. It uses XSLT-3.0 content value templates.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" expand-text="true">
<xsl:output method="xml" indent="yes" />
<xsl:mode on-no-match="shallow-copy" />
<xsl:strip-space elements="*" /> <!-- Remove space between elements -->
<xsl:template match="RECORD">
<xsl:copy>
<xsl:copy-of select="#*" />
<title>{title[1]}{if (title[1]) then ' - ' else ''}<xsl:value-of select="content" separator=" " /></title>
<xsl:apply-templates select="node() except (title,content)" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
It's output is as desired.
If you want to separate the <content> elements with a -, too, you can simplify the core <title> expression to
<xsl:value-of select="title|content" separator=" - " />
EDIT:
All I changed was replacing chapter with RECORD, and it's working fine with Saxon-HE 9.9.1.4J. The only difference in the output is that the title element is always at the first position, but that shouldn't matter. I also added a directive to remove space between elements.

How to handle print and sign event notifications from docusign api?

We have event notifications set up to send us a notification request for user actions.
I am trying to validate the document status to figure out if an user has signed a document. When the user has signed the document using docusign, I can capture the status from TabStatuses in the request.
However, I am not unable to figure out a way to handle the scenario where an user has opted to print and sign as the response for Print and Sign notifications does not include the TabStatuses with the status.
I have tried to go through the documentation to figure out if there is a way to confirm that the user has opted to print and sign the document, but I couldn't find what I was looking for. I do get DocumentStatus which returns a name node signed_on_paper_<reference_id> but it doesn't seem like the best approach to validate that the user has opted to print and sign.
Also in the case of multiple signers, what would be the best way to identify the status of each signer.
Sample response I received when a user opted to print and sign:
<EnvelopeStatus>
<RecipientStatuses>
<RecipientStatus>
<Type>
Signer
</Type>
<Email>
sdasari#plxs.com.au
</Email>
<UserName>
Shyam Dasari
</UserName>
<RoutingOrder>
1
</RoutingOrder>
<Sent>
2019-10-15T16:23:38.06
</Sent>
<Delivered>
2019-10-15T16:23:50.15
</Delivered>
<Signed>
2019-10-15T16:24:35.167
</Signed>
<DeclineReason xsi:nil="true" />
<Status>
Completed
</Status>
<RecipientIPAddress>
115.70.163.1
</RecipientIPAddress>
<ClientUserId>
7422
</ClientUserId>
<CustomFields />
<AccountStatus>
Active
</AccountStatus>
<EsignAgreementInformation>
<AccountEsignId>
e17f1e7a-2d2f-49e7-bdc6-gibberish
</AccountEsignId>
<UserEsignId>
75eda468-405c-48a3-bf8c-gibberish
</UserEsignId>
<AgreementDate>
2019-10-15T16:23:50.15
</AgreementDate>
</EsignAgreementInformation>
<RecipientId>
e1e8e99a-b89f-4d5c-aa27-gibberish
</RecipientId>
</RecipientStatus>
</RecipientStatuses>
<TimeGenerated>
2019-10-15T16:24:55.6107604
</TimeGenerated>
<EnvelopeID>
530aa34b-1991-4bc6-b374-gibberish
</EnvelopeID>
<Subject>
Shyam Dasari has sent you a document to review and sign
</Subject>
<UserName>
Legal Gateway Sandbox
</UserName>
<Email>
callum#testsoftware.com.au
</Email>
<Status>
Completed
</Status>
<Created>
2019-10-15T16:23:37.67
</Created>
<Sent>
2019-10-15T16:23:38.093
</Sent>
<Delivered>
2019-10-15T16:23:50.307
</Delivered>
<Signed>
2019-10-15T16:24:35.167
</Signed>
<Completed>
2019-10-15T16:24:35.167
</Completed>
<ACStatus>
Original
</ACStatus>
<ACStatusDate>
2019-10-15T16:23:37.67
</ACStatusDate>
<ACHolder>
Legal Gateway Sandbox
</ACHolder>
<ACHolderEmail>
callum#test.com.au
</ACHolderEmail>
<ACHolderLocation>
DocuSign
</ACHolderLocation>
<SigningLocation>
Online
</SigningLocation>
<SenderIPAddress>
115.70.163.1
</SenderIPAddress>
<EnvelopePDFHash />
<CustomFields>
<CustomField>
<Name>
AccountId
</Name>
<Show>
false
</Show>
<Required>
false
</Required>
<Value>
12345
</Value>
<CustomFieldType>
Text
</CustomFieldType>
</CustomField>
<CustomField>
<Name>
AccountName
</Name>
<Show>
false
</Show>
<Required>
false
</Required>
<Value>
Legal Gateway
</Value>
<CustomFieldType>
Text
</CustomFieldType>
</CustomField>
<CustomField>
<Name>
AccountSite
</Name>
<Show>
false
</Show>
<Required>
false
</Required>
<Value>
demo
</Value>
<CustomFieldType>
Text
</CustomFieldType>
</CustomField>
</CustomFields>
<AutoNavigation>
true
</AutoNavigation>
<EnvelopeIdStamping>
true
</EnvelopeIdStamping>
<AuthoritativeCopy>
false
</AuthoritativeCopy>
<DocumentStatuses>
<DocumentStatus>
<ID>
4321
</ID>
<Name>
sid_0a_2s_rando_doc_2_1405
</Name>
<TemplateName />
<Sequence>
1
</Sequence>
<DocumentFields>
<DocumentField>
<Name>
reference_id
</Name>
<Value>
gibberish:1iKFJ0:gibberish-Cw
</Value>
</DocumentField>
</DocumentFields>
</DocumentStatus>
<DocumentStatus>
<ID>
2
</ID>
<Name>
Signed-on-Paper_more-gibberish-aa27-bafd4d393c02
</Name>
<TemplateName />
<Sequence>
2
</Sequence>
</DocumentStatus>
</DocumentStatuses>
</EnvelopeStatus>
If a user opted to sign using docusign's esignature, I get TabStatuses in the response which help me identify the current state of the document.
<TabStatuses>
<TabStatus>
<TabType>
SignHere
</TabType>
<Status>
Signed
</Status>
<XPosition>
699
</XPosition>
<YPosition>
754
</YPosition>
<TabLabel>
Signature 1_SignHere_gibberish_id
</TabLabel>
<TabName />
<DocumentID>
2460
</DocumentID>
<PageNumber>
1
</PageNumber>
</TabStatus>
</TabStatuses>
I am using the docusign api version 2.
When a user signs on paper there are no tabs.
Moreover, there's no way for you to know what paper was actually signed.
When the envelope is complete, you'll find an additional document in it, which is the paper that was faxed into the system. That is the only information you get back from a user that signs on paper.
(We strongly discourage use of paper, and if one uses it - there are certain limitations to what we can support).

XML parsing for nested tags using python

i would need a help on how to parse xml files with nested tags taking the user input as attribute value of a particular tag.
for eg:
if xml code has 12 mappings and we want to select the below mapping name "m_IF1_TD_SALESORDER_STG_PR4_VBPA_BUSINESS_PARTNER" as user input and thereby printing the particular mapping details.
<MAPPING NAME="m_IF1_TD_SALESORDER_STG_PR4_VBPA_BUSINESS_PARTNER" DESCRIPTION="Data Mapping for loading Sales Order Business Partners from the staging database for PR4." OBJECTVERSION="1" ISVALID="YES" VERSIONNUMBER="1">
<TRANSFORMATION NAME="sq_STG_PR4_VBPA" DESCRIPTION="" TYPE="Source Qualifier" OBJECTVERSION="1" REUSABLE="NO" VERSIONNUMBER="1">
<TRANSFORMFIELD NAME="MANDT" DESCRIPTION="" DATATYPE="string" PORTTYPE="INPUT/OUTPUT" PRECISION="3" SCALE="0" PICTURETEXT="" DEFAULTVALUE="" EXPRESSION="MANDT" EXPRESSIONTYPE="GENERAL"/>
<TRANSFORMFIELD NAME="VBELN" DESCRIPTION="" DATATYPE="string" PORTTYPE="INPUT/OUTPUT" PRECISION="10" SCALE="0" PICTURETEXT="" DEFAULTVALUE="" EXPRESSION="VBELN" EXPRESSIONTYPE="GENERAL"/>
<TRANSFORMFIELD NAME="POSNR" DESCRIPTION="" DATATYPE="decimal" PORTTYPE="INPUT/OUTPUT" PRECISION="6" SCALE="0" PICTURETEXT="" DEFAULTVALUE="" EXPRESSION="POSNR" EXPRESSIONTYPE="GENERAL"/>
<TRANSFORMFIELD NAME="PARVW" DESCRIPTION="" DATATYPE="string" PORTTYPE="INPUT/OUTPUT" PRECISION="2" SCALE="0" PICTURETEXT="" DEFAULTVALUE="" EXPRESSION="PARVW" EXPRESSIONTYPE="GENERAL"/>
I would suggest using the XML ElementTree module of python.
It is very simple to use. For example:
import xml.etree.ElementTree as ET
tree = ET.parse('/filename.xml')
root = tree.getroot()
for subchild in root.findall('subchildName'):
print(subchild.get('subchildAttribute')

Pentaho Data Integration Mapping

I am using Pentaho Data Integration, I created a new transformation and I have 2 steps in it....1 is a CSV file of my data, the second is an Excel file with two columns one is are the state names and the other the sort form of that state name, Example ("New York" "NY")
In my CSV file I have a state columns with the state names "New York" I want to use my excel file to map "New York" with "NY"
I have googled this all day with no clear answer...can anyone help?
You can use Merge Join. Using this you can merge both the files and select the desired columns. Before merging, you have to sort those files according to fields which use are using for mapping. In your case, it will be state name.
I would recommend you to use stream lookup to do this task. Check the test transformation attached. It will do your task.
<?xml version="1.0" encoding="UTF-8"?>
<transformation-steps>
<steps>
<step>
<name>EXCEL</name>
<type>DataGrid</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<field>
<name>State</name>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
</field>
<field>
<name>Short_state</name>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
</field>
</fields>
<data>
<line> <item>New York</item><item>TX</item> </line>
<line> <item>Texas</item><item>TX</item> </line>
</data>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>392</xloc>
<yloc>80</yloc>
<draw>Y</draw>
</GUI>
</step>
<step>
<name>CSV</name>
<type>DataGrid</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<field>
<name>Full_state_name</name>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
</field>
</fields>
<data>
<line> <item>New York</item> </line>
<line> <item>Texas</item> </line>
</data>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>511</xloc>
<yloc>169</yloc>
<draw>Y</draw>
</GUI>
</step>
<step>
<name>Stream lookup</name>
<type>StreamLookup</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<from>EXCEL</from>
<input_sorted>N</input_sorted>
<preserve_memory>Y</preserve_memory>
<sorted_list>N</sorted_list>
<integer_pair>N</integer_pair>
<lookup>
<key>
<name>Full_state_name</name>
<field>State</field>
</key>
<value>
<name>State</name>
<rename>State</rename>
<default/>
<type>String</type>
</value>
<value>
<name>Short_state</name>
<rename>Short_state</rename>
<default/>
<type>String</type>
</value>
</lookup>
<cluster_schema/>
<remotesteps> <input> </input> <output> </output> </remotesteps> <GUI>
<xloc>510</xloc>
<yloc>79</yloc>
<draw>Y</draw>
</GUI>
</step>
</steps>
<order>
<hop> <from>EXCEL</from><to>Stream lookup</to><enabled>Y</enabled> </hop>
<hop> <from>CSV</from><to>Stream lookup</to><enabled>Y</enabled> </hop>
</order>
<notepads>
</notepads>
<step_error_handling>
</step_error_handling>
</transformation-steps>

Resources