我想转换一个 XML 文档。我的 XSLT 代码正在工作,并且可以正确转换(在 XMLPad 中测试),但现在我想在我的 VB.NET 程序中对其进行转换。问题是我不想从.xsl
文件中加载 XSLT 代码。我将它硬编码在一个函数中,但我遇到了Illegal characters in path
异常。
有没有可能这样:
Public Class xsltTransformCode
Public Function transformationXSLTcode() As String
Return "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>" &
"<xsl:strip-space elements='*'/>" &
"<xsl:output method='xml' indent='yes'/>" &
"<xsl:key name='AreaByPosition' match='Area' use='Position'/>" &
"<xsl:template match='@*|node()'>" &
"<xsl:copy><xsl:apply-templates select='@*|node()'/></xsl:copy>" &
"</xsl:template>" &
"<!-- for the first Area in each Position -->" &
"<xsl:template match='Area[generate-id() = generate-id(key('AreaByPosition', Position)[1])]'>" &
"<Area>" &
"<!-- copy in the Position element once only -->" &
"<xsl:apply-templates select='Position'/>" &
"<!-- copy in all sub-elements except Position from all matching Areas -->" &
"<xsl:apply-templates select='key('AreaByPosition', Position)/*[not(self::Position)]'/>" &
"</Area>" &
"</xsl:template>" &
"<!-- ignore all other Area elements -->" &
"<xsl:template match='Area'/>" &
"</xsl:stylesheet>"
End Function
End Class
因为当我尝试加载它时出现异常
Dim xsltTransformerCode As New xsltTransformCode()
Dim xsltTransCompiled As New XslCompiledTransform()
xsltTransCompiled.Load(xsltTransformerCode.transformationXSLTcode())