Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - XSLT: Reduce XML to fit Schema >Thread Next - Re: XSLT: Reduce XML to fit Schema Re: XSLT: Reduce XML to fit SchemaTo: NULL Date: 8/14/2009 4:27:00 PM C. Marco wrote: > I'm sure this can be done with XSLT and I guess it surely doesn't take > much effort to do this. Can anyone give me a little hint on how to > solve this? Thank you! Do you expect the author of the XSLT stylesheet to read the schema and author an appropriate XSLT stylesheet? Someone skilled with schemas and stylesheet can certainly do that. Or do you expect the XSLT stylesheet to be generic and pull in the schema and then based on the schema to generate the output? That is far from being trivial, with the complexity the W3C XML schema language has. Here is my attempt to write a stylesheet based on the XML input and the schema you have provided, it simply copies everything recursively besides the 'c' and 'z' elements: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:test="http://test/" version="1.0"> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="test:c | test:z"/> </xsl:stylesheet> That way you get <?xml version="1.0" encoding="UTF-8"?> <a xmlns="http://test/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://test/ test2009081401Xsd.xml"> <b>Node B</b> <m> <x>Node X1</x> <y>Node Y1</y> <m> <x>Node X2</x> <y>Node Y2</y> </m> </m> </a> -- Martin Honnen http://msmvps.com/blogs/martin_honnen/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
