Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XSLT: Reduce XML to fit Schema

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent