尝试进行转换时出现以下错误:
无法将属性和命名空间节点添加到父元素 在添加了text,comment,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>
答案 0 :(得分:2)
问题:如错误所示,&#34; text,comment,pi或 子元素 节点&#34;可能不会介入xsl:attribute
和接收该属性的元素。
解决方案:将xsl:attribute
语句移至立即,在您要添加属性的td
元素下方。