File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XSLT Remove Node by Attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT Remove Node by Attribute" Watch "XSLT Remove Node by Attribute" New topic
Author

XSLT Remove Node by Attribute

Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
I'm trying to figure out how to do an XSLT transformation to remove certain nodes from an XML file based on specific attribute matches within a node.

Here is the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<body>
<out id="100" />
<out id="101" />
<out id="102" />
<out id="103" />
</body>

Say I want a new XML file that would exclude the nodes with id="101" and id="103".

Desired Output:

<body>
<out id="100" />
<out id="102" />
</body>

How would I do this with XSLT?

Thank you!

Drew
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, you would start with an identity transformation. Then add templates that match the nodes you want to delete, and have those templates not do anything with them.

You can find the identity transformation in the XSLT Recommendation.
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
I've been playing around with this but I'm not seeing what I'm expecting.

Are web browsers (e.g. IE7, Firefox 2.0) capable of displaying transformed XML?

Drew
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I believe they are, but I haven't used the feature myself. Would you like to describe your problem a bit more?
Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
I didn't have any luck viewing transformations in IE7 - it would only show the original XML file. However, Firefox 2.0 worked when I installed an extension to "View Transformed XML Source".

Maybe the browsers only show XML > HTML transformations?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XSLT Remove Node by Attribute