I’m looking do some sort of transform from INI to XML, the INI syntax is simple. I’m not looking to sed/awk/grep, this really should be done in XML tools.
Can this be done with regular XSL?
I have heard of Xflat, but can I do that from tools compiled in C? Such as xsltproc or xmlstarlet.
Generic INI syntax is like this…
[section]
option = values
which would be in xml like this…
<section>
<option>values</option>
</section>
Any help would be very appreciated.
Yes, and XSLT 2.0 provides more facilities than XSLT 1.0 for processing text. Very complex text processing has been implemented in XSLT, including a general LR(1) parser, used for building parsers for specific grammars, such as JSON and XPath.
In particular, learn about
unparsed-text(), the various string functions, including the ones that allow using regular expressions (matches(),tokenize()andreplace()) and also the<xsl:analyze-string>instruction.XSLT 1.0 also has string functions (as provided by XPath 1.0), however it lacks the regular expressions capabilty/functions and there is nothing such as the XSLT 2.0 function
unparsed-text(). Among the most useful XPath 1.0 string functions are:substring(),substring-before(),substring-after(),starts-with(),string-length(),concat(), and especially thetranslate()function.One can “read” a file by using an entity in a DTD, as Mads Hansen has explained in his answer. Another way is to read the file in the program that initiates the transformation, then to pass the file’s content as a string parameter to the transformation.
Update: The OP has now provided specific data, so that a complete solution is possible:
when this transformation is applied on any XML document (not used) and if the file at
C:\temp\delete\test.inihas the following content:the wanted, correct result is produced: