我试图执行XSD文件的XSLT转换。我的目标是最终从XSD创建SQL。到目前为止好,这是我有:XSLT转换创建StackoverflowException
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();
}
}
}
这是一个失败的XSLT文件:
<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>
我总是得到StackoverflowException在System.Data.SqlXml.dll。我怎样才能停止递归?如果不存在xs:元素,它不应该停止吗?
编辑: 原始代码是从here它已经有错误。我试图通过简化XSLT来修复它,直到只剩下错误。
你的样式表应该做什么?您发布的样本没有任何意义,因为它不会输出任何内容。它基本上是对同一个模板的递归“调用”,因此产生了一个SOE。 – 2010-07-21 14:09:38
在我的问题结尾处看到我的编辑 – codymanix 2010-07-21 14:29:28