Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 07-18-2022 11:21 PM
Hi Team ,
Could you please help me in working with XML tag's in Nifi. I've a scenario where i need to look for the parent xml tag value in entire document, the corresponding child xml tag value should match. if it is not matching we should copy the parent xml tag value to the corresponding specified child tag.
here the parent tag is <OriginalQTY name=" 5.000"> and the child tag should match is <OriginalORDEREDPURCHASEQUANTITY> So every time <OriginalORDEREDPURCHASEQUANTITY> should match <OriginalQTY> value in name.
<Document>
<PURCHPURCHASEORDERHEADERV2ENTITY>
<VENDORACCOUNT>XXXXX</VENDORACCOUNT>
<CURRENCYCODE>ZAR</CURRENCYCODE>
<OriginalQTY name=" 1.000">
<PURCHPURCHASEORDERLINEV2ENTITY>
<PURCHASEORDERNUMBER>PO-XXXXXXX</PURCHASEORDERNUMBER>
<LINENUMBER>0000000100</LINENUMBER>
<PURCHASEPRICE>???</PURCHASEPRICE>
<ITEMNUMBER>XXXXXXXXX</ITEMNUMBER>
<CONFIRMEDQUANTITY> 0.000</CONFIRMEDQUANTITY>
<OriginalORDEREDPURCHASEQUANTITY> 7.000</OriginalORDEREDPURCHASEQUANTITY>
</OriginalQTY>
<OriginalQTY name=" 5.000">
<PURCHPURCHASEORDERLINEV2ENTITY>
<PURCHASEORDERNUMBER>PO-XXXXXXXXX</PURCHASEORDERNUMBER>
<LINENUMBER>0000000100</LINENUMBER>
<PURCHASEPRICE>???</PURCHASEPRICE>
<ITEMNUMBER>A4634101302</ITEMNUMBER>
<CONFIRMEDQUANTITY> 0.000</CONFIRMEDQUANTITY>
<OriginalORDEREDPURCHASEQUANTITY> 7.000</OriginalORDEREDPURCHASEQUANTITY>
</OriginalQTY>
</PURCHPURCHASEORDERHEADERV2ENTITY>
</Document>
Created 07-20-2022 01:48 PM
Hi,
Are you looking to copy the value from the parent tag name attribute "<OriginalQTY name=" 5.000">" to the value of the child tag "<OriginalORDEREDPURCHASEQUANTITY>" so that its matching all the time? If so you can try the TransformXML processor with the following script:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Document/PURCHPURCHASEORDERHEADERV2ENTITY/OriginalQTY/PURCHPURCHASEORDERLINEV2ENTITY/OriginalORDEREDPURCHASEQUANTITY">
<xsl:copy>
<xsl:value-of select="../../@name"/>
</xsl:copy>
</xsl:template>
</xsl:transform>If you find that helpful please accept solution. Thanks
Created 07-19-2022 10:12 AM
@mburgess Could you please help on this? thank you!!
Created 07-20-2022 01:48 PM
Hi,
Are you looking to copy the value from the parent tag name attribute "<OriginalQTY name=" 5.000">" to the value of the child tag "<OriginalORDEREDPURCHASEQUANTITY>" so that its matching all the time? If so you can try the TransformXML processor with the following script:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Document/PURCHPURCHASEORDERHEADERV2ENTITY/OriginalQTY/PURCHPURCHASEORDERLINEV2ENTITY/OriginalORDEREDPURCHASEQUANTITY">
<xsl:copy>
<xsl:value-of select="../../@name"/>
</xsl:copy>
</xsl:template>
</xsl:transform>If you find that helpful please accept solution. Thanks
Created on 07-21-2022 06:03 AM - edited 07-21-2022 06:03 AM
Yes that's the requirement.
Thank you so much @SAMSAL , it worked. perfectly, Could you please help me any sources to get used to these xml scripts.