Using POSTMAN, how to get the SequenceNumber value and set as Environment Variable?
<?xml version="1.0" standalone="yes" ?>
<Response type="Heartbeat">
<Field name="SequenceNumber">270164614</Field>
<Field name="Status">ok</Field>
</Response>
Related
I need to take an XML file and create a new output file.
During creation of the output file, I need to total the quantities by material
This is my input file: -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<MATERIAL>Material1</MATERIAL>
<SALES_DIST>FS</SALES_DIST>
<REGION>North</REGION>
<FIELDNM001>EA</FIELDNM001>
<MONTH>2020-01-01</MONTH>
<FIELDNM002>1</FIELDNM002>
</record>
<record>
<MATERIAL>Material1</MATERIAL>
<SALES_DIST>FS</SALES_DIST>
<REGION>North</REGION>
<FIELDNM001>EA</FIELDNM001>
<MONTH>2020-01-01</MONTH>
<FIELDNM002>1</FIELDNM002>
</record>
</data-set>
What I need to end up with is a file like this: -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<MATERIAL>Material1</MATERIAL>
<SALES_DIST>FS</SALES_DIST>
<REGION>North</REGION>
<FIELDNM001>EA</FIELDNM001>
<MONTH>2020-01-01</MONTH>
<FIELDNM002>2</FIELDNM002>
</record>
</data-set>
Any ideas on what the xslt document should look like to achieve this?
Many thanks in advance.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<MATERIAL>Material1</MATERIAL>
<SALES_DIST>FS</SALES_DIST>
<REGION>North</REGION>
<FIELDNM001>EA</FIELDNM001>
<MONTH>2020-01-01</MONTH>
<FIELDNM002>2</FIELDNM002>
</record>
</data-set>
Starting from this reply, the following works for me using xsltproc on Linux:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gt="http://www.gtech.com/lsp/2009-09-23"
exclude-result-prefixes="gt">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<MATERIAL><xsl:value-of select="//MATERIAL" /></MATERIAL>
<SALES_DIST><xsl:value-of select="//SALES_DIST" /></SALES_DIST>
<REGION><xsl:value-of select="//REGION" /></REGION>
<FIELDNM001><xsl:value-of select="//FIELDNM001" /></FIELDNM001>
<MONTH><xsl:value-of select="//MONTH" /></MONTH>
<FIELDNM002><xsl:value-of select="sum(//FIELDNM002[.])"/></FIELDNM002>
</record>
</data-set>
</xsl:template>
</xsl:stylesheet>
If other fields of the records in xml are not equals, it takes only the first records' values
With my limited knowledge of XSL programming I have come up with this code:
(Post updated: XSLT is now working - Updated for the benefit of others if at all!)
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:nm="http://fsag.de/BusinessTransaction"
xmlns:env="http://www.w3.org/2001/12/soap-envelope"
exclude-result-prefixes="env">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/nm:Responses">
<xsl:copy-of select="/"/>
</xsl:template>
<xsl:template match="/Envelope">
<nm:Responses xmlns:nm="http://fsag.de/BusinessTransaction">
<BTEMessages/>
<SystemContext/>
<Error>
<xsl:copy-of select="Body"/>
</Error>
</nm:Responses>
</xsl:template>
</xsl:stylesheet>
The purpose of the is to process the file (at the end of the post) and get the result below:
Required result for 'Error' file :
<?xml version="1.0" encoding="UTF-8"?>
<nm:Response xmlns:nm="http://fsag.de/BusinessTransaction">
<BTEMessages/>
<SystemContext/>
<Error>
<Body>
<Response status="1">
<Description>DESC</Description>
<Errors>
<Error>500</Error>
</Errors>
</Response>
</Body>
</Error>
</nm:Response>
Required result for 'Response' file:
<?xml version="1.0" encoding="UTF-8"?>
<nm:Response xmlns:nm="http://fsag.de/BusinessTransaction">
<BTEMessages>
<InOrderContext xmlns:n0="http://fsag.de/BusinessTransaction">
<SendTimestamp>01-06-2017:0506230000</SendTimestamp>
</InOrderContext>
<SystemContext>
<Client>FDP</Client>
<CorrelationId>34553FTG25543SFD134</CorrelationId>
<BusinessContext>RECONCL</BusinessContext>
</SystemContext>
</BTEMessages>
</nm:Response>
*File 1: Error *
<Envelope >
<Body>
<Response status="1">
<Description>DESC</Description>
<Errors>
<Error>500</Error>
</Errors>
</Response>
</Body>
</Envelope>
File 2: Response:
<?xml version="1.0" encoding="UTF-8"?>
<nm:Response xmlns:nm="http://fsag.de/BusinessTransaction">
<BTEMessage>
<InOrderContext>
<SendTimestamp>01-06-2017:0506230000</SendTimestamp>
</InOrderContext>
<SystemContext>
<Client>FDP</Client>
<CorrelationId>34553FTG25543SFD134</CorrelationId>
<BusinessContext>RECONCL</BusinessContext>
</SystemContext>
</BTEMessage>
</nm:Response >
When i try to run the XSL is failing. Please any help here?
XSL updated with working version.
I am using xslt to add namespace and new attribute to root node.I need to make this xml file
<?xml version="1.0" encoding="utf-8"?>
<Document Hub="" DocType="Invoice" ID="" BatchNumber="" DocumentCreatedDate="2016-08-09">
<HeaderInformation></HeaderInformation>
<Summary></Summary>
</Document>
To be Like
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="http://Anylink" Hub="ADP" DocumentCreatedDate="2016-08-09" PartnershipId="123">
<HeaderInformation></HeaderInformation>
<Summary></Summary>
</Document>
I am trying to read the number element value using below xsl.
XML:
<message channel-id="64E523E5-7A27-4343-A62A-AA8FBD24EB59">
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<insertResponse>
<sys_id>4342e2a24fb142005b0e4fe18110c7f3</sys_id>
<number>INC0010038</number>
</insertResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</message>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<message>
<send-parameters>
<agent-parameter>
<name>IncidentNumber</name>
<value><xsl:value-of select="message/s:Envelope/s:Body/t:insertResponse/t:number" /></value>
</agent-parameter>
</send-parameters>
</message>
</xsl:template>
</xsl:stylesheet>
The output i am getting is as below.
<?xml version="1.0" encoding="UTF-8"?>
<message>
<send-parameters>
<agent-parameter>
<name>IncidentNumber</name>
<value>4342e2a24fb142005b0e4fe18110c7f3
INC0010038</value>
</agent-parameter>
</send-parameters>
</message>
The value element is getting value from both sys-id and number tags 4342e2a24fb142005b0e4fe18110c7f3INC0010038. I want to read only number tag from the xml. I am sure that i am missing something very basic here. Please help me with that.
Regards,
Kiran
Try out the following:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
exclude-result-prefixes="env xsl">
<xsl:template match="/">
<message>
<send-parameters>
<agent-parameter>
<name>IncidentNumber</name>
<value>
<xsl:value-of select="message/env:Envelope/env:Body/insertResponse/number" />
</value>
</agent-parameter>
</send-parameters>
</message>
</xsl:template>
</xsl:stylesheet>
As stated by Micheal you are missing namespace definition in your stylesheet. Once you do that your code is good to go
I've read a lot of examples about ignore namespaces but can't seem to bring this concept to fruition inside template match.
Here's my sample xml:
<?xml version="1.0"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Response xmlns:ResB="http://www.aaa.com/v1" xmlns:dpconf="http://www.datapower.com/param/config" xmlns:exsl="http://xmlns.opentechnology.org/xslt-extensions/common" xmlns="http://www.aaa.com/v2">
<Status>
<Code>00000</Code>
</Status>
</Response>
</soapenv:Body>
</soapenv:Envelope>
And I can't have the namespace in the ouptut. Here's an example of the desired output:
<A>
<Transformed>0000</Transformed>
</A>
This isn't outputting my nodes, so how can I have an xslt to match the Response node and work off of that?
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//*[local-name() = 'Response']">
<A>
<Transformed><xsl:value-of select="Status/Code"/></Transformed>
</A>
Why would you want to ignore the namespace? Just declare it and use it.
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:v2="http://www.aaa.com/v2"
exclude-result-prefixes="v2"
>
<xsl:template match="v2:Response">
<A>
<Transformed>
<xsl:value-of select="v2:Status/v2:Code" />
</Transformed>
</A>
</xsl:template>
</xsl:stylesheet>