xml
  • xslt
  • xslcompiledtransform
  • 2011-05-30 72 views 0 likes 
    0

    我想将xml从一种格式转换为使用c#中的XslCompiledTransform的其他格式。下面是样式表和源XML,Reg。 XSLT转换中的xmlns问题

    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='' 
                  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> 
               "); 
    

    我收到的时候我要去使用XslCompiledTransform“状态开始令牌文本会导致一个无效的XML文档中的转型以下情况例外。确保THAŧ如果要编写XML片段,ConformanceLevel设置将设置为ConformanceLevel.Fragment或Conformanc eLevel.Auto。“ 如果我从根元素中删除xmlns属性,一切正常。为什么会发生这种情况,我如何解决这个问题

    回答

    0

    更改样式表

    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

    哦马丁..非常感谢你。我已经把我的头几个小时:) – VJAI 2011-05-30 11:33:06

    相关问题