How to save XML to a file

How do you save the translated XML to an actual file on disk? I am new to XML / XSLT and I am trying to figure this out. I can't seem to find any examples that will work for me. For example, I just want to save the file in c: \ temp \ text.xls. How to save it? Should I use java or .net or some other programming language / api? I was hoping that XSL would just save the file.

+4
source share
4 answers

XSL can't do anything on its own. This is just a definition for converting an XML file to something else. To do something with it, you need to run XSL Transform in a program or using a tool such as XML Spy.

Update

Here is a simple example that I wrote a few years ago in VBScript:

Dim xml, xsl, htm, fso, flOut Set xml = CreateObject("MSXML2.DOMDocument") Set xsl = CreateObject("Msxml2.DOMDocument") Set fso = CreateObject("Scripting.FileSystemObject") xml.load WScript.Arguments(0) xsl.load WScript.Arguments(1) htm = xml.transformNode(xsl) Set flOut = fso.CreateTextFile(WScript.Arguments(2)) flOut.Write htm flOut.close 

I called it xmlTrfm.vbs. Use it like this:

 xmlTrfm.vbs [sourceFileName].xml [transformFileName].xsl [outputFileName].[ext] 

The file extension for the name of the output file obviously depends on the format that the XSL transform generates, usually xml, html or txt, but can be almost anything.

+4
source

Almost every XSLT processor allows you to initiate a conversion from the command line . One of the arguments is the file in which you want to save the result of the conversion.

<strong> Examples:

  • Saxon 9.x : java net.sf.saxon.Transform -s:source -xsl:stylesheet -o:output

  • MSXML6 : msxsl.exe %xml% %xsl% -o %out% -u '6.0' -t %param[ name="value"]%

  • XQSharp : xslt.exe -s %xml% -o %out% -r 1 -t %xsl% %param[ name="value"]%

  • .NET 2.0+ (XslCompiledTransform): nxslt2.exe %xml% %xsl% -t -o %out%%param[ name="value"]%

  • AltovaXML (XML-SPY): AltovaXML.exe -xslt2 %xsl% -in %xml% -out %out%%param[ name="value"]%

In 2. to 5. above %xml% is the path to the file containing the XML document, %xsl% is the path to the file containing the main XSLT stylesheet, `% out% is the path to the file where the conversion result should be saved .

+2
source

Yes, you cannot save it with XSLT - which languages ​​can you use?

+1
source

Perhaps (I reflect) your difficulty is that you are using XSLT transform in a browser? In this case, you will have difficulties, because browsers, for security reasons, do not allow writing to filestore in the usual way.

If not, explain how you use the XSLT transform.

0
source

Source: https://habr.com/ru/post/1412886/


All Articles