I have an xslt file containing an xsl variable that I use as a lookup table.
<xsl:variable name="TestLookup">
<lookup code="A" means="Test A"/>
<lookup code="B" means="Test B"/>
<lookup code="C" means="Test C"/>
</xsl:variable>
Then I call it that.
<xsl:value-of select="document('')/*/xsl:variable[@name='TestLookup']/lookup[@code=current()]/@means"/>
When I call the Transform method in .NET, I get the following errors:
An error occurred while loading document ''
This operation is not supported for a relative URI.
It basically tells me that he cannot find the document.
I need a way to create a lookup table in an xslt file and be able to call it using the Transform command in .NET.
This article had the same problem, but I did not see the answer. Something about the p / 2 function?
He also listed node -set (), but I cannot find a good article about using node -set as a lookup table.
using document () function in .NET XSLT generates an error
Adding additional
.NET code
' get the xml from SQL
Dim xmlData As String = sqlXmlReader.Item("XmlData").ToString()
' read the xslt file
Using styleSheet = New StreamReader("XSLTTestFile.xslt")
' load the stylesheet from a resource
Using styleSheetReader As XmlReader = XmlReader.Create(styleSheet)
Dim xslt = New XslCompiledTransform()
Dim xsltSettings = New XsltSettings(True, False)
xsltSettings.EnableDocumentFunction = True
' load the stylesheet for transformation
xslt.Load(styleSheetReader, xsltSettings, New XmlUrlResolver())
Using stringWriter As New System.IO.StringWriter
' transform the xml document along with the stylesheet
Dim xmlDoc = New XmlDocument()
xmlDoc.LoadXml(xmlData)
xslt.Transform(xmlDoc, Nothing, stringWriter)
' dump the transformation to the browser control
_htmlString.Append(stringWriter.ToString())
End Using
End Using
End Using