0

When using the Console Runner, I am using an XSLT transform to convert the NUnit XML output to a custom HTML report using transform with --result option. I need to access some environment variables within the XSLT file, and the only way I know of doing that is to pass them as parameters to the transform. Is there a way that I can pass parameters to the XSLT transform from the command-line? Or is there some other way I can do this?

Ken
  • 72
  • 8

2 Answers2

0

If you can integrate an XSLT 2 or 3 processor in your NUnit console runner (or it directly uses one, I don't know) then there is an XPath function to access environment variables https://www.w3.org/TR/xpath-functions/#func-environment-variable. Using XSLT 1.0 processors you would need to use processor specific extension function mechanism to call into the underlying platform (e.g. Java, .NET) to read out an environment variable value.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Yes, this should work. NUnit uses the .NET runtime to perform the transformation, so use the .NET documentation to determine any limitations which may exist. – Charlie Aug 22 '22 at 15:28
  • I wasn't aware that the NUnit Console supported XSLT 2 or 3. Is there anything special that needs to be done for that other than to include the appropriate namespace in the XSLT file? – Ken Aug 22 '22 at 17:32
  • @Ken, I am not saying that NUnit (Console) supports XSLT 2 or 3, I am just saying that XSLT 2/3 support that function `environment-variable` from XPath natively or that the .NET platform with XslCompiledTransform as the "built-in" XSLT 1 processor allows ways to extend XSLT by calls to the .NET platform via extension "scripts"/"objects". Whether NUnit allows any of that is something I don't know. – Martin Honnen Aug 22 '22 at 17:45
  • @MartinHonnen. Sorry, I was replying to Charlie's response. I guess I should have specified that in my reply. He seemed to imply that NUnit supported XSLT 2 or 3. However, from what I have been able to find so far, .NET does not support XSL 2 or 3 yet. – Ken Aug 22 '22 at 21:05
0

I think I may have found a solution. I can pass the environment variables to NUnit as parameters that I want to have in my HTML report. At the end of the test run, the result XML file will contain the parameters containing my env variables. The XSLT can then get those parameters from the XML file and format them into the HTML file.

Ken
  • 72
  • 8