XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
David CorleySubject: 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.


Documentpmd-all.xml
PMD xml report.

Postnext
Ivan PedruzziSubject: Moving data from one xml file to another xml file based on attribute value
Author: Ivan Pedruzzi
Date: 26 May 2006 09:46 AM
Hi David,

In order to generate multiple outputs from a single transformation you have to use XSLT 2.0 (attached solution) or EXSLT.

If your processor is XSLT 1.0 only and does not support EXSLT you could run the same style-sheet multiple time passing the priority as parameter.

Ivan Pedruzzi
Stylus Studio Team


Documentpriority.xsl

Posttop
David CorleySubject: 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.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.