【问题标题】:Error: Attribute and namespace nodes cannot be added to the parent element错误:不能将属性和命名空间节点添加到父元素
【发布时间】:2016-09-22 23:35:55
【问题描述】:

尝试进行转换时出现以下错误:

属性和命名空间节点不能添加到父元素 在已添加文本、评论、pi 或子元素节点之后。

下面是我用来做转换的函数

Public Function Transform(ByVal doc As XmlNode, ByVal stylesheet As XmlDocument) As String
    Dim trans As XslCompiledTransform = New XslCompiledTransform()
    trans.Load(stylesheet)
    Dim settings As XmlWriterSettings = New XmlWriterSettings()
    settings.OmitXmlDeclaration = False
    settings.ConformanceLevel = ConformanceLevel.Fragment
    settings.CloseOutput = False

    Dim writer As System.IO.StringWriter = New System.IO.StringWriter()
    trans.Transform(doc, XmlWriter.Create(writer, settings))

    Return writer.ToString()
End Function

以下是我的 xsl 中的违规代码

<xsl:template name="Calendar">
    <xsl:variable name="dateRef"><xsl:value-of select="@dateRef"/></xsl:variable>
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td style="padding-top: 10px">
                        <span style="position:absolute; display:none" fieldName="{//Form/@name}.{Name}" initialDate="{@initialDate}" futureBound="{@futureBound}" pastBound="{@pastBound}">
                            <xsl:attribute name="ID">date<xsl:value-of select="$dateRef"/></xsl:attribute>
                        </span>
                        <!-- When I comment out the line below my page loads, but the intended content doesn't -->
                        <xsl:attribute name="ID">date<xsl:value-of select="$dateRef"/></xsl:attribute>
                        <xsl:call-template name="calendarContents"/>
                </td>
            </tr>
        </table>
</xsl:template>

【问题讨论】:

    标签: xml vb.net xslt system.xml


    【解决方案1】:

    问题: 如错误所示,“文本、评论、pi 或 子元素 节点”可能不会介入 @ 之间987654321@ 和接收该属性的元素。

    解决方案:xsl:attribute 语句上移至立即在您要添加属性的td 元素下方。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 2017-11-27
      相关资源
      最近更新 更多