I have a plain text file structured like this:
!ITEM_NAME
Item value
!ANOTHER_ITEM
Its value
...
Is it possible to get with XSLT a file similar to:
<?xml version="1.0" encoding="UTF-8" ?>
<document>
<ITEM_NAME>Item value</ITEM_NAME>
<ANOTHER_ITEM>Its value</ANOTHER_ITEM>
...
</document>
EDIT
I am sorry I haven't clearly stated before. I am trying to accomplish this transformation with the Visual Studio 2005 XSLT engine. I have tried both of the provided solutions, and I am sure that are correct. But Visual Studio 2005 doesn't know the unparsed-text function.
This XSLT 2.0 transformation:
when appliedon any XML document (not used) and having the provided text residing in the local file
C:\temp\delete\Text.txt
:produces the wanted, correct result:
To test more completely, we put this text in the file:
The transformation again produces the wanted, correct result:
If you can use XSLT 2.0 you could use
unparsed-text()
...Text File (Do not use the text file as direct input to the XSLT.)
XSLT 2.0 (Apply this XSLT to itself (use the stylesheet as the XML input). You'll also have to change the path to your text file. You might have to change the encoding too.)
XML Output