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

  • Home
  • SEARCH
  • 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 1042193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:28:10+00:00 2026-05-16T15:28:10+00:00

I’m trying to transform the content of a CHM (Microsoft HTML Help) file’s index

  • 0

I’m trying to transform the content of a CHM (Microsoft HTML Help) file’s index which holds structure information in very arbitrary HTML lists with XSL (see the first code snippet—the actual index file’s structure is a bit different, but the important parts are there). I’ve checked out the index of several CHM files but the ul, li tag structures are never the same. Only one thing is static: there are param tags which are holding information on chapter, section, whatever titles and links to their HTML

Because of this I’m trying to rely only on the depth information of the certain param tags to convert the list into an XML structure (primarily into a DocBook structure—see the second code snippet).

<ul>
  <li>
    <param attr="value"/>
    <ul>
      <li>
        <param attr="value"/>
        <ul>
          <li>
            <param attr="value"/>
          </li>
        </ul>
      </li>
      <li>
        <param attr="value"/>
        <ul>
          <li>
            <param attr="value"/>
          </li>
          <li>
            <param attr="value"/>
          </li>
        </ul>
      </li>
      <li>
        <param attr="value"/>
        <ul>
          <li>
            <param attr="value"/>
          </li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

I’ve managed to transform some indexes (similar to the previous code snippet) to a DocBook structure, but the problem is that my XSL stylesheet is not generic enough. If anyone has an idea to transform a similar HTML list into a DocBook structure, using only the depth information of the param tags, please give me some pointers.

So for example the param tags with a depth of X would be transformed to a book element, params with a depth of X + 1 would be transformed to chapter, et cetera—of course always properly nested.

<book>
  <title>value1</title>
  <chapter>
    <title>value2</title>
    <section>
      <title>value3</title>
    </section>
  </chapter>
  <chapter>
    <title>value4</title>
    <section>
      <title>value5</title>
    </section>
    <section>
      <title>value6</title>
    </section>
  </chapter>
  <chapter>
    <title>value7</title>
    <section>
      <title>value8</title>
    </section>
  </chapter>
</book>
  • 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-16T15:28:10+00:00Added an answer on May 16, 2026 at 3:28 pm

    If your main problem is how to produce a different element depending on the depth in the input tree, then the following stylesheet demonstrates one way of doing it: first, figuring out the nesting level by count()ing elements on the ancestor-or-self axis, and then using xsl:element to create an element with a dynamically determined name.

    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
      <xsl:template match="li">
        <xsl:variable name="depth" select="count(ancestor-or-self::li)"/>
        <xsl:variable name="tag">
          <xsl:choose>
            <xsl:when test="$depth = 1">book</xsl:when>
            <xsl:when test="$depth = 2">chapter</xsl:when>
            <xsl:otherwise>section</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:element name="{$tag}">
          <xsl:apply-templates/>
        </xsl:element>
      </xsl:template>
    
      <xsl:template match="param">
        <title>
          <xsl:value-of select="@attr"/>
        </title>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Edit. And here’s another way of doing the same. This uses different templates for matching the source element at different depths. This may be a bit easier to read, as it eliminates the need of creating a dynamically named element.

    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
      <xsl:template match="li[count(ancestor-or-self::li) = 1]">
        <book>
          <xsl:apply-templates/>
        </book>
      </xsl:template>
    
      <xsl:template match="li[count(ancestor-or-self::li) = 2]">
        <chapter>
          <xsl:apply-templates/>
        </chapter>
      </xsl:template>
    
      <xsl:template match="li[count(ancestor-or-self::li) &gt; 2]">
        <section>
          <xsl:apply-templates/>
        </section>
      </xsl:template>
    
      <xsl:template match="param">
        <title>
          <xsl:value-of select="@attr"/>
        </title>
      </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.