Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Replace element text within xml >Thread Next - Re: Replace element text within xml Re: Replace element text within xmlTo: NULL Date: 9/2/2005 8:09:00 PM
"Dan Kelley" <DanKelley@d...> wrote in message
news:ECA376ED-22A2-434B-B314-97D2B1946DA0@m......
> Thanks for both of your help. I tried the suggested solution, however
> there
> was a problem. It replaced the first <test-suite> element, but then output
> all of the xml between the elements as text, completely stripping out all
> of
> the following xml elements and attributes.
>
> I tried google, but all articles seem to assume a solid understanding of
> xslt, or contain the same content as
> www.dpawson.co.uk/xsl/sect2/identity.html.
Below is a transformation, which copies all nodes with the exception that it
removes all "-" from any element's name:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[contains(name(),'-')]">
<xsl:element name="{translate(name(),'-','')}"
namespace="{namespace-uri()}">
<xsl:copy-of select="namespace::*"/>
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
When the above transformation is applied on your original source xml (made
just a little more complex by adding namespace prefixes) :
<x:test-results name="name" xmlns:x="x:x">
<test-suite name="name">
<results>
<test-case name="name">
...
</test-case>
</results>
</test-suite>
</x:test-results>
the wanted result is produced:
<x:testresults name="name" xmlns:x="x:x">
<testsuite name="name">
<results>
<testcase name="name">
...
</testcase>
</results>
</testsuite>
</x:testresults>
Cheers,
Dimitre Novatchev
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
