[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
Thanks Aaron! I couldn’t figure out how to get that to work for more than one string, but yours works great! Eric From: aarondamommio@gmail.com [mailto:aarondamommio@gmail.com]
On Behalf Of Aaron DaMommio 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"?>
</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
-- |
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]