Thanks Aaron! I couldn't figure out how to get that to work for more than one 
string, but yours works great!

Eric

From: [email protected] [mailto:[email protected]] On Behalf Of 
Aaron DaMommio
Sent: Wednesday, April 10, 2013 5:30 PM
To: Eric Nordlund
Cc: [email protected]
Subject: Re: [docbook-apps] Trying to remove some elements from an XML file 
with XSLT

My approach was to set up a base template that copies everything over, and then 
add one template that catches entry elements that don't match either of the two 
String element values you specified, writing nothing out for them.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <!-- by default, copy everything over -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <!-- except entry elements that don't have String children matching one of 
two specific values-->
    <xsl:template match="entry[not(String[ . = 'XML options'] or String[.='Diff 
options'])]"/>
</xsl:stylesheet>

The results I got when I ran your input through that XSL were:

<?xml version="1.0" encoding="UTF-8"?><serialized version="14.2" 
xml:space="preserve">
            <map>
                        <entry>
                                    <String>Diff options</String>
                                    <Boolean>false</Boolean>
                        </entry>



                        <entry>
                                    <String>XML options</String>
                                    <Boolean>false</Boolean>
                        </entry>
                </map>
</serialized>

On Wed, Apr 10, 2013 at 6:48 PM, Eric Nordlund 
<[email protected]<mailto:[email protected]>> wrote:
Hello, I'm trying to filter a massive XML preferences file to only keep certain 
elements I want, and remove the rest. The file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<serialized version="14.2" xml:space="preserve">
            <map>
                        <entry>
                                    <String>Diff options</String>
                                    <Boolean>false</Boolean>
                        </entry>
                        <entry>
                                    <String>Network connection settings</String>
                                    <Boolean>false</Boolean>
                        </entry>
                        <entry>
                                    <String>Saxon XSLT options</String>
                                    <Boolean>false</Boolean>
                        </entry>
                        <entry>
                                    <String>Templates options</String>
                                    <Boolean>false</Boolean>
                        </entry>
                        <entry>
                                    <String>XML options</String>
                                    <Boolean>false</Boolean>
                        </entry>
                </map>
</serialized>

How can I apply an XSLT that will keep the <entry> blocks for "XML options" and 
"Diff options" and the parent structure but get rid of the other <entry> blocks?

Thanks,

Eric Nordlund
Customer Documentation and Training
Cray Inc.
901 5th Ave
Seattle, WA 98164
(206)701-2232<tel:%28206%29701-2232>




--
--------------------------------------
Aaron DaMommio: Husband, father, writer, juggler, and expert washer of dishes.
- My blog: http://aarondamommio.blogspot.com
- Need a juggler?  http://amazingaaronjuggler.blogspot.com/
=======================================

Reply via email to