开发者

Reg. xmlns issue in XSLT transformation

I'm trying convert xml from one format to other using the XslCompiledTransform in c#. Below is the stylesheet and the source xml,

string xslMarkup = @"<?xml version='1.0'?>
                            <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'  xmlns:msxsl='urn:schemas-microsoft-com:xslt' exclude-result-prefixes='msxsl' version='1.0'>
                                <xsl:output method='xml' indent='yes'/>
                                <xsl:template match='/NewDataSet'>
                                    <Root>
                                        <xsl:apply-templates select='Violations'/>
                                    </Root>
                                </xsl:template>
                                <xsl:template match='Violations'>
                                    <detail ccr_id='{@ViolationID}' 
                                            assn_id=''      
                                            member_id='' 
                                            local_ccr_id='' 
                                            create_date='' 
                                            inspect_date='' 
                                            respond_date='' 
                                            last_inspect_date='' 
                                            status='' 
                                            active=''
                                            type=''
                                            description=''
                                            type_desc=''
                                            owner_action=''
                                            acc_action=''
                                    开发者_C百科        acc_action_date=''
                                            last_acc_action=''
                                            last_acc_action_date=''
                                            ccr_name=''
                                            location='' />
                                  </xsl:template>
                            </xsl:stylesheet>";

            XDocument xmlTree =
                XDocument.Parse(@"<?xml version='1.0' encoding='utf-8'?> 
                                    <NewDataSet xmlns='www.reefpt.com/caliberapi'>  
                                        <Violations>
                                              <ViolationID>66</ViolationID> 
                                              <ViolationNumber>201fgh4</ViolationNumber>
                                        </Violations>
                                        <Violations>
                                              <ViolationID>66</ViolationID> 
                                              <ViolationNumber>2011fgh</ViolationNumber>
                                        </Violations>
                                    </NewDataSet>
                                ");

I'm getting the following exception when I'm going the transformation using XslCompiledTransform "Token Text in state Start would result in an invalid XML document. Make sure tha t the ConformanceLevel setting is set to ConformanceLevel.Fragment or Conformanc eLevel.Auto if you want to write an XML fragment." If I remove the xmlns attribute from the root element everything works fine. Why this happens and how I can fix this?


Change the stylesheet to

string xslMarkup = @"<?xml version='1.0'?>
                            <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'  xmlns:msxsl='urn:schemas-microsoft-com:xslt' xmlns:df="www.reefpt.com/caliberapi" exclude-result-prefixes='msxsl df' version='1.0'>
                                <xsl:output method='xml' indent='yes'/>
                                <xsl:template match='/df:NewDataSet'>
                                    <Root>
                                        <xsl:apply-templates select='df:Violations'/>
                                    </Root>
                                </xsl:template>
                                <xsl:template match='df:Violations'>
                                    <detail ccr_id='{@ViolationID}' 
                                            assn_id=''      
                                            member_id='' 
                                            local_ccr_id='' 
                                            create_date='' 
                                            inspect_date='' 
                                            respond_date='' 
                                            last_inspect_date='' 
                                            status='' 
                                            active=''
                                            type=''
                                            description=''
                                            type_desc=''
                                            owner_action=''
                                            acc_action=''
                                            acc_action_date=''
                                            last_acc_action=''
                                            last_acc_action_date=''
                                            ccr_name=''
                                            location='' />
                                  </xsl:template>
                            </xsl:stylesheet>";
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜