Introduction
This article specifically records the Syntax problems in the conversion process of XSLT style sheets.
Incorrect value and attribute inversion
The style sheet has been modified several times, but an error is reported as before. The error message is as follows:
[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. ".
Obviously, the XML task has told you the cause of the error, that is, the attribute or namespace definition cannot follow an existing document.
Correct syntax:
<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>
Incorrect syntax-when the salesorderid is converted to an XML task, once the value of the source salesorderid is written, the latter is incorrect with attribute, and the former is 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>
The attribute detailid must be defined before salesorderid 71774 in the correct output segment.
<?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>
Related Resources
XSLT tutorial
For more bi articles, see the Bi series Essays (SSIS, SSRS, SSAs, MDX, SQL Server, to help others quickly see these articles in the recommendation bar of the biwork blog.
Conversion error records of XSLT style sheets in Microsoft Bi SSIS series-XML tasks