Looking for a way to transform an xml using xlst based on predefined values
I am very new to xslt, please pardon me, if this is a basic question.
Input xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<project groups="mygroup" name="test1/project1" path="current_dir" />
<project groups="mygroup" name="test2/project2" path="some_dir/foo"/>
<project groups="mygroup" name="test3/project3" path="new_dir/bar"/>
<project groups="mygroup" name="test4/project4" path="current_dir/baz"/>
</manifest>
Looking for a output
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<project groups="mygroup" name="test1/project1" path="myfolder" />
<project groups="mygroup" name="test2/project2" path="myfolder/step1"/>
<project groups="mygroup" name="test3/project3" path="test_folder/>
</manifest>
Basically, change the path to a predefined custom path and exclude the lines that does not have a custom path.
if name="test1/project1" change path="myfolder"
if name="test2/project2" change path="myfolder/step1"
if name="test3/project3" change path="test_folder"
remove line for everything else
I started with the below code, but this one modifies path to same one ( considering that there are no conditional checks ). I would like to add conditions to check for "name" attribute, and change the "path" attribute to a corresponding path, and also drop for which a custom path is not needed. For example test4/project4 in the above example
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/manifest/project/@path">
<xsl:attribute name="path">Custom Path</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
pathattribute.