• 微软BI 之SSIS 系列


    开篇介绍

    此文章专门记录 XSLT 样式表转换过程中的语法问题

    错误一 值与属性的倒置

    修改了几次样式表,但还是一如既往的报错,报错信息如下:

    [XML Task] Error: An error occurred with the following error message: "Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added.".

    很明显 XML Task 已经告知了错误的原因,即属性或者命名空间的定义不能跟随已经存在的文之后。

    正确的写法:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/"> 
        <newsalesorder>
        <xsl:for-each select="SalesOrder/SalesOrderDetail">
            <salesorderdetail>
                <salesorderID>
                    <xsl:attribute name="detailID">
                        <xsl:value-of select="SalesOrderDetailID"/>
                    </xsl:attribute>
                    <xsl:value-of select="SalesOrderID"/>
                </salesorderID> 
            </salesorderdetail>
        </xsl:for-each> 
        </newsalesorder>
    </xsl:template>
    </xsl:stylesheet> 

    错误的写法 - SalesOrderID 在 XML Task 转换时,源 SalesOrderID 的值一经写出,后面再跟 Attribute 是不正确的,应该是 Attribute 在前。

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/"> 
        <newsalesorder>
        <xsl:for-each select="SalesOrder/SalesOrderDetail">
            <salesorderdetail>
                <salesorderID>
                    <xsl:value-of select="SalesOrderID"/>
                    <xsl:attribute name="detailID">
                        <xsl:value-of select="SalesOrderDetailID"/>
                    </xsl:attribute>
                </salesorderID> 
            </salesorderdetail>
        </xsl:for-each> 
        </newsalesorder>
    </xsl:template>
    </xsl:stylesheet> 

    正确的输出片段中 detailID 这个 Attribute 属性应该要定义在 SalesOrderID 71774 之前。

    <?xml version="1.0" encoding="utf-8"?>
    <newsalesorder>
      <salesorderdetail>
        <salesorderID detailID="110562">71774</salesorderID>
      </salesorderdetail>
      <salesorderdetail>
        <salesorderID detailID="110563">71774</salesorderID>
      </salesorderdetail>
      <salesorderdetail>
        <salesorderID detailID="110567">71776</salesorderID>
      </salesorderdetail>

    相关资源

    XSLT 教程

    更多 BI 文章请参看 BI 系列随笔列表 (SSIS, SSRS, SSAS, MDX, SQL Server)  如果觉得这篇文章看了对您有帮助,请帮助推荐,以方便他人在 BIWORK 博客推荐栏中快速看到这些文章。

  • 相关阅读:
    在ASP.NET 2.0中使用WebParts
    Asp.net生成静态页面原理
    提高ASP.Net应用程序性能的十大方法
    Web2.0之Tag标签原理实现浅析
    ASP.NET 2.0中的URL映射
    动态加载控件UserControl到页面上:视图状态问题
    C#自动登录网页浏览页面 抓取数据
    .NET Framework 类库提供的命名空间
    一个用于热部署的框架设想
    重构如何进行?
  • 原文地址:https://www.cnblogs.com/biwork/p/3996560.html
Copyright © 2020-2023  润新知