[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Using XSLT as a namespace filter...

Subject: Re: Using XSLT as a namespace filter...
From: Nathan Potter <ndp@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 13 Jan 2009 18:47:49 -0800
Re:  Using XSLT as a namespace filter...
Solution:

The previously posted transform works correctly to "band-pass" only elements from a particular namespace. The example inputs I previously provided were flawed.

Transform:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foo="http://foo.org/ns/foo" >
<xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'/>


        <xsl:template match="foo:*">
            <xsl:copy >
                <xsl:call-template name="textAndattributes" />
                <xsl:apply-templates />
            </xsl:copy>
        </xsl:template>

<xsl:template match="*"><xsl:apply-templates /></xsl:template>

<xsl:template match="@*|text()" />

<xsl:template name="textAndattributes" ><xsl:copy-of select="text()|@*" /></xsl:template>

</xsl:stylesheet>


Source Document:



<?xml version="1.0" encoding="UTF-8"?>
<A name="rootElement" xmlns="http://foo.org/ns/foo" xmlns:foo="http://foo.org/ns/foo ">


    <B name="wooStuff" type="otherXML">
        <W xmlns="http://foo.org/ns/woo" >Some Stuff</W>
        <W xmlns="http://foo.org/ns/woo" >Some more stuff</W>
    </B>


<C name="site_netCode"> <d name="outside" /> <Thing1 xmlns="http://www.thing.net/thing/1.1" > <foo:d name="inside">inside's text node</foo:d> </Thing1> </C> <C name="site_netCode"> <d name="outside" /> <d name="inside">inside's text node</d> </C>

</A>



Correct Result:

<?xml version="1.0" encoding="UTF-8"?>
<A xmlns="http://foo.org/ns/foo" xmlns:foo="http://foo.org/ns/foo" name="rootElement">
<B name="WCS" type="otherXML">
</B>
<C name="site_netCode">
<d name="outside"/>
<foo:d xmlns="http://www.thing.net/thing/1.1" name="inside">inside's text node</foo:d>
</C>
<C name="site_netCode">
<d name="outside"/>
<d name="inside">inside's text node</d>
</C>
</A>



============================================================ Nathan Potter Oregon State University, COAS ndp at coas.oregonstate.edu 104 Ocean. Admin. Bldg. 541 737 2293 voice Corvallis, OR 97331-5503 541 737 2064 fax

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.