docbook-apps

  • 1.  Trying to remove some elements from an XML file with XSLT

    Posted 04-10-2013 23:49
    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:


    <serialized version="14.2" xml:space="preserve">

    <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>

    </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




  • 2.  Re: [docbook-apps] Trying to remove some elements from an XML file with XSLT

    Posted 04-11-2013 00:30
    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.


    <xsl:stylesheet version="1.1" xmlns:xsl="
    http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>


    <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:

    <serialized version="14.2"
    xml:space="preserve">

    <entry>
    <String>Diff options</String>
    <Boolean>false</Boolean>
    </entry>



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

    </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:***
    > *
    >
    > ** **
    >
    >
    > <serialized version="14.2" xml:space="preserve">
    >
    > <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>****
    >
    >
    ****
    >
    > </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/
    =======================================



  • 3.  RE: [docbook-apps] Trying to remove some elements from an XML file with XSLT

    Posted 04-11-2013 01:28
    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
    Sent: Wednesday, April 10, 2013 5:30 PM
    To: Eric Nordlund
    Cc: docbook-apps@lists.oasis-open.org
    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.


    <xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>


    <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:

    <serialized version="14.2" xml:space="preserve">

    <entry>
    <String>Diff options</String>
    <Boolean>false</Boolean>
    </entry>



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

    </serialized>

    On Wed, Apr 10, 2013 at 6:48 PM, Eric Nordlund <nordlund@cray.com<mailto: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:


    <serialized version="14.2" xml:space="preserve">

    <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>

    </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/
    =======================================