Sorry about that - they are actual results. I got tripped by the
dangers of cut and paste. I had a number of versions of the problem
and I got the pieces mixed up in the last post.
So, one last post on this thread to get it correct:
Solution:
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
" xmlns:thing="http://www.thing.net/thing/1.1">
<B name="woo" 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" />
<thing:Thing1 >
<foo:d name="inside">inside's text node</foo:d>
</thing:Thing1>
</C>
<C name="site_netCode">
<d name="outside" />
<d name="anotherOutside">another'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"
xmlns:thing="http://www.thing.net/thing/1.1"
name="rootElement">
<B name="woo" type="otherXML">
</B>
<C name="site_netCode">
<d name="outside"/>
<foo:d name="inside">inside's text node</foo:d>
</C>
<C name="site_netCode">
<d name="outside"/>
<d name="anotherOutside">another's text node</d>
</C>
</A>
On Jan 14, 2009, at 1:38 AM, Ken Starks wrote:
Its usually better to post _actual_ results, so we don't all have to
wonder
whether you intended to change name="wooStuff" to name="WCS".
Nathan Potter wrote:
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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
============================================================
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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--