I tried to perform XSLT transform of a XSD file. My goal is in the end to create SQL from XSD. So far so good, this is what I have:
void Convert()
{
XPathDocument xpathDoc = new XPathDocument(@"myschema.xsd");
string xslPath = @"convert.xsl";
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(xslPath, new XsltSettings(true, true), null);
using (FileStream fs = File.Create(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "output.sql")))
{
try
{
transform.Transform(xpathDoc, null, fs);
}
catch
{
fs.Close();
}
}
}
This is the XSLT file which is failing:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Get schema nodes from this schema and any included schemas -->
<xsl:variable name="contents" select="/|document(//xs:include/@schemaLocation)" />
<xsl:template match="*" >
<xsl:for-each select="$contents" >
<xsl:apply-templates select=".//xs:element" />
</xsl:for-each>
</xsl:template>
<xsl:template match="xs:element">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
I always get a StackoverflowException in System.Data.SqlXml.dll. How can I stop the recursion? Shouldn't it stop if no xs:element remain?
EDIT: The original code was from here and it already had the error. I tried to fix it by simplifying the XSLT until only the error remained.