Subject:Moving data from one xml file to another xml file based on attribute value Author:David Corley Date:25 May 2006 11:20 AM
Hey,
I have an xml PMD report containing information on violations the PMD tool found in my java code. Each violation is assigned a priority from 3 to 8. I would like to be able to run a transformation against the main xml file to output seperate xml files for the following:
priority 3 only
priority 3+4 only
priority 3+4+5 only
priority 3+4+5+6 only
priority 3+4+5+6+7 only
If I could get some idea how to do the first 2 of these, I'm sure I could work out the rest.
I'm attaching the original xml file containing the data so you can get an idea of the structure.
NB..I do want to output xml only, I don't want to generate html. The root node attribute values in the output xml should be identical to those in the original xml.
Subject:Moving data from one xml file to another xml file based on attribute value Author:David Corley Date:26 May 2006 09:55 AM
Hey Ivan,
I managed to find a solution to the problem shortly after I posted yesterday. I'm gonna put it up here in case anyone else has the same problem:
<?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"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="pmd/file/violation[@priority='4']"/>
<xsl:template match="pmd/file/violation[@priority='5']"/>
<xsl:template match="pmd/file/violation[@priority='6']"/>
<xsl:template match="pmd/file/violation[@priority='7']"/>
<xsl:template match="pmd/file/violation[@priority='8']"/>
</xsl:stylesheet>
The above example copied all priority 3 data from the original xml file to a new xml file but did not copy the priority 4-8 rules.
I create several variations of the above to remove unwanted priorities levels.