OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


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 <nordlund@cray.com> 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

 




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


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]