- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
copying Parent XML tag value to child tag value
- Labels:
-
Apache NiFi
Created ‎07-18-2022 11:21 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@mburgess Could you please help on this? thank you!!
Created ‎07-20-2022 01:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
