Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6948165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:47:11+00:00 2026-05-27T13:47:11+00:00

I’m looking do some sort of transform from INI to XML, the INI syntax

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:47:12+00:00Added an answer on May 27, 2026 at 1:47 pm

    Can this be done with regular XSL?

    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() and replace()) 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 the translate() 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:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:variable name="vText" select=
     "unparsed-text('file:///c:/temp/delete/test.ini')"/>
    
     <xsl:variable name="vLines" as="xs:string*" select=
       "tokenize($vText, '&#xD;?&#xA;')[.]"/>
    
     <xsl:variable name="vLineCnt" select="count($vLines)"/>
    
     <xsl:variable name="vSectLinesInds" as="xs:integer*" select=
      "for $i in 1 to $vLineCnt
         return
           if(starts-with(normalize-space($vLines[$i]), '['))
             then $i
             else ()
      "/>
    
     <xsl:variable name="vSectCnt" select="count($vSectLinesInds)"/>
    
     <xsl:template match="/">
      <xsl:for-each select="$vSectLinesInds">
        <xsl:variable name="vPos" select="position()"/>
        <xsl:variable name="vInd" as="xs:integer" select="."/>
    
         <xsl:variable name="vthisLine" as="xs:string"
              select="$vLines[$vInd]"/>
    
        <xsl:variable name="vNextSectInd" select=
         "if($vPos eq $vSectCnt)
            then
              $vLineCnt +1
            else
              $vSectLinesInds[$vPos +1]
         "/>
    
       <xsl:variable name="vInnerLines" select=
       "$vLines
           [position() gt current()
          and
            position() lt $vNextSectInd
           ]
    
       "/>
    
       <xsl:variable name="vName" select=
        "tokenize($vthisLine, '\[|\]')[2]"/>
    
       <xsl:element name="{$vName}">
        <xsl:for-each select="$vInnerLines">
          <xsl:variable name="vInnerParts" select=
          "tokenize(., '[ ]*=[ ]*')"/>
    
          <xsl:element name="{$vInnerParts[1]}">
            <xsl:value-of select="$vInnerParts[2]"/>
          </xsl:element>
        </xsl:for-each>
      </xsl:element>
      </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on any XML document (not used) and if the file at C:\temp\delete\test.ini has the following content:

    [section1]
    option1 = values1
    option2 = values2
    option3 = values3
    option4 = values4
    option5 = values5
    
    [section2]
    option1 = values1
    option2 = values2
    option3 = values3
    option4 = values4
    option5 = values5
    
    [section3]
    option1 = values1
    option2 = values2
    option3 = values3
    option4 = values4
    option5 = values5
    

    the wanted, correct result is produced:

    <section1>
       <option1>values1</option1>
       <option2>values2</option2>
       <option3>values3</option3>
       <option4>values4</option4>
       <option5>values5</option5>
    </section1>
    <section2>
       <option1>values1</option1>
       <option2>values2</option2>
       <option3>values3</option3>
       <option4>values4</option4>
       <option5>values5</option5>
    </section2>
    <section3>
       <option1>values1</option1>
       <option2>values2</option2>
       <option3>values3</option3>
       <option4>values4</option4>
       <option5>values5</option5>
    </section3>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.