开发者

xsl:for-each not supported in this context

开发者 https://www.devze.com 2023-01-01 11:15 出处:网络
I have this XSLT document : <xsl:stylesheet version=\"1.0\" xmlns:mstns=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://www.w3.org/2001/XMLSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\

I have this XSLT document :

<xsl:stylesheet version="1.0" xmlns:mstns="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/MyDocRootElement">
    <xs:schema id="DataSet" targetNamespace="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" >
        <xs:element name="DataSet" msdata:IsDataSet="true">
            <xs:complexType>
                <xs:choice maxOccurs="unbounded">
                    <xs:element name="Somename"> </xs:element>
                    <xs:element name="OtherName">

                    </xs:element>
                    <!-- FOR EACH NOT SUPPORTED? -->
                    <xsl:for-each select="OtherElements/SubElement">
                             <xs:element name="OtherName">

                            </xs:element>
                    </xsl:for-each>
                </xs:choice>
            </xs:complexType>
        </xs:element>
    </xs:schema>
</xsl:template>
</xsl:stylesheet>

I have a validation error saying that the "for-each element is not supported in this context"

开发者_JAVA百科

I am guessing it has something to do with the xs namespace validation.

Any ideas on how can I make this work? (Exclude validation?)

Thanks Alex


Update:

@alexbf, who submitted the problem has stated in a comment that he doesn't perform any validation and the error is result of running the transformation with XslCompiledTransform (.NET).

I have verified that the stylesheet compiles and executes with XslCompiledTransform without any problems -- both in VS2008 and using the nxslt.exe command-line utility.

The reason for the error is in the code that is not shown -- the code that that prepares and initiates the transformation.


It rarely, if ever, makes sense to validate an XSLT stylesheet!

After all, the XSLT processor does this task even better -- performing additional semantic validation, that cannot always be expressed in the XSD schema for XSLT.

A second problem is that you are validating the XSLT stylesheet with a schema not for XSLT, but for another document type...

Recommendation: Never try to validate your XSLT stylesheet. Validation has meaning for your custom document types, such as the source XML document(s) involved in the XSLT processing or the result document from this XSLT processing.


I believe this is an IDE bug.

The XSLT is valid, it compiles fine.


Update :

The problem was related to something else in the XSLT. I had stripped down the XSLT for the sake of this post but I realized the problem really was in the section I removed. The error message was misleading.

It was related to a <xsl:comment> element I used to keep temporary XSLT code.

I removed the whole <xsl:comment> section and it now works perfectly

Sorry for the confusion, thanks for your help.

0

精彩评论

暂无评论...
验证码 换一张
取 消