tags:

views:

55

answers:

3

Hi!

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"&gt;
<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"

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

A: 

I believe this is an IDE bug.

The XSLT is valid, it compiles fine.

GSerg
A: 

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.

Dimitre Novatchev
I understand, but I'm not really validating the XSLT. The error is thrown by the XSLT processor (.NET : XslCompiledTransform)
alexbf
@alexbf: Your 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 you haven't shown -- that prepares and initiates the transformation.
Dimitre Novatchev
@alexbf: show the code that creates the `XslCompiledTransform` instance and calls its `Transform()` method. The problem is there.
Dimitre Novatchev
A: 

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.

alexbf