Icon

xml replacer and insert with xml demo files using xslt

Demonstration Workflow using XSLT to update Names and insert new elements on one XML based on IDs

It reads Identifier and Name from both XMLS using XPath, then finds the changes to names for existing IDs, and applies XSLT to update them.

In addition, where there is a new ID, this is a new that will be added to the original XML by an xslt update



@takbb Brian Bates 26 Mar 2024

Process the EXISTING IDs. Where the name has changed for a given ID, build the portion of the xslt thatwill update the name Process NEW IDs. Build the xml for each <element> to place in the xslt to add a new element where the ID did not previouslyexist read all elements from updated xml read all elements from existing xml determine which are existing IDs andwhich are new IDs convert back to xml datatypeThis is the Existing XML file datatransform XMLfix xml datatypefor xsltThis is the XSLT template tobe applied to the existing XMLto update it basedon the XML updatescreate templatesconvert to variablesto populate xslt templateinclude the xsl templatefor each identifierwithin the base xlst templatebase xmlcreate an xsl templatefor each name to be updatedremove default namespace(KNIME uses XSLT 1.0 whichmakes handling default namespacesmore challenging)xml with some changesget id and namefrom base xmlmatch on idto find updatednames(top)new IDs (bottom)identifierswith changed nameget id and name fromupdated xmlrename rightname toupdated-nameBring the row for the Existing and the row for New Elementstogetheradd empty row ifno new rows to addmake into basic string withoutthe xml header line, as we want to simply insert this directly into xslt templateconcatenate the xml rows into onethese are the <element> entriesfor the new IDsRead main template xslt from fileremove default namespace(KNIME uses XSLT 1.0 whichmakes handling default namespacesmore challenging)convert backto xml datatypetransformed XMLString To XML XSLT String To XML GroupBy Table Rowto Variable String Manipulation XML Reader String Manipulation String Manipulation XML Reader XPath Joiner Rule-basedRow Filter XPath Column Rename Column Appender Add Empty Rows String Manipulation GroupBy XML Reader String Manipulation String To XML Column Filter Process the EXISTING IDs. Where the name has changed for a given ID, build the portion of the xslt thatwill update the name Process NEW IDs. Build the xml for each <element> to place in the xslt to add a new element where the ID did not previouslyexist read all elements from updated xml read all elements from existing xml determine which are existing IDs andwhich are new IDs convert back to xml datatypeThis is the Existing XML file datatransform XMLfix xml datatypefor xsltThis is the XSLT template tobe applied to the existing XMLto update it basedon the XML updatescreate templatesconvert to variablesto populate xslt templateinclude the xsl templatefor each identifierwithin the base xlst templatebase xmlcreate an xsl templatefor each name to be updatedremove default namespace(KNIME uses XSLT 1.0 whichmakes handling default namespacesmore challenging)xml with some changesget id and namefrom base xmlmatch on idto find updatednames(top)new IDs (bottom)identifierswith changed nameget id and name fromupdated xmlrename rightname toupdated-nameBring the row for the Existing and the row for New Elementstogetheradd empty row ifno new rows to addmake into basic string withoutthe xml header line, as we want to simply insert this directly into xslt templateconcatenate the xml rows into onethese are the <element> entriesfor the new IDsRead main template xslt from fileremove default namespace(KNIME uses XSLT 1.0 whichmakes handling default namespacesmore challenging)convert backto xml datatypetransformed XMLString To XML XSLT String To XML GroupBy Table Rowto Variable String Manipulation XML Reader String Manipulation String Manipulation XML Reader XPath Joiner Rule-basedRow Filter XPath Column Rename Column Appender Add Empty Rows String Manipulation GroupBy XML Reader String Manipulation String To XML Column Filter

Nodes

Extensions

Links