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 7920307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:09:56+00:00 2026-06-03T16:09:56+00:00

I am working with some pretty messy HTML source content and trying to structure

  • 0

I am working with some pretty messy HTML source content and trying to structure a single ol into one where attributes (from the source) determine if certain list items should be put into their own sub-list. The list is also broken up into several ol, but I think that can be gotten around by ignoring the parent node.

Source:

<div class="x-popup-text c3" id="POPUP172050488">
  <p>To add multiple balance adjustments:</p>
  <ol>
    <li class="kadov-p-CStep">
      <p class="Step">Check 
      <span class="hcp1">Add to queue</span> at the bottom of the page.</p>
    </li>
    <li class="kadov-p-CStep">
      <p class="Step">At the top of the page, enter the 
      <span class="hcp1">Account</span>. &#160;This is a three-part field:</p>
    </li>
    <li class="kadov-p-CStepBullet">
      <p class="StepBullet">In the first part, select the bank number &#160;from the drop-down list.</p>
    </li>
    <li class="kadov-p-CStepBullet">
      <p class="StepBullet">In the second part, select the application code from the drop-down list.</p>
    </li>
    <li class="kadov-p-CStepBullet">
      <p class="StepBullet">In the third part, enter the account number or click the account search button 
      <img src="../mag_glass_blue_bkgrd.gif" x-maintain-ratio="TRUE" width="16" height="16" border="0" class="hcp2 c1" /> to find it.</p>
    </li>
  </ol>
  <ol start="3">
    <li class="kadov-p-CStep">
      <p class="Step">Enter the start date for the adjustment in the 
      <span class="hcp1">From</span> field or click the calendar button 
      <img src="../calendar.gif" x-maintain-ratio="TRUE" width="16" height="18" border="0" class="hcp2 c2" /> to select the date.</p>
    </li>
    <li class="kadov-p-CStep">
      <p class="Step">Enter the end date for the adjustment in the 
      <span class="hcp1">Through</span> field or click the calendar button 
      <img src="../calendar.gif" x-maintain-ratio="TRUE" width="16" height="18" border="0" class="hcp2 c2" /> to select the date.</p>
    </li>
  </ol>
  <p class="StepText">
  <span class="hcp1">Tip:</span> &#160;The Through date must be the same as or after the From date.</p>
  <ol start="5">
    <li class="kadov-p-CStep">
      <p class="Step">For each balance you want to adjust, do the following:</p>
    </li>
    <li class="kadov-p-CStepBullet">
      <p class="StepBullet">In the table at the bottom of the page, find the appropriate 
      <span class="hcp1">Balance Type</span> for the adjustment.</p>
    </li>
    <li class="kadov-p-CStepBullet">
      <p class="StepBullet">Enter the 
      <span class="hcp1">Amount</span> of the adjustment to the right of the balance type.</p>
    </li>
    <li class="kadov-p-CStepBullet">
      <p class="StepBullet">If you want the adjustment to appear on the customer's statement, check the 
      <span class="hcp1">Print on Statements</span> checkbox that corresponds to the adjustment amount you entered.</p>
    </li>
  </ol>
  <ol start="6">
    <li class="kadov-p-CStep">
      <p class="Step">Click 
      <span class="hcp1">Add</span>.</p>
    </li>
    <li class="kadov-p-CStep">
      <p class="Step">Repeat steps 2 through 7 for each additional adjustment you want to add.</p>
    </li>
    <li class="kadov-p-CStep">
      <p class="Step">Click the 
      <span class="hcp1">View queue</span> link at the bottom of the page to enter the Work Queue and apply the adjustments.</p>
    </li>
  </ol>
</div>

I know, it’s a mess.

So, essentially:
Any li with @class=’kadov-p-CStep’ should be a first-level li.
Any following-sibling li with @class=’kadov-p-CStepBullet’ before the next ‘kadov-p-Step’ li should go in a subordinate list underneath its new parent.

Elsewhere on here, I found a formula for selecting a node-set intersection:

$ns1[count(.|$ns2)=count($ns2)] 

Which I have tried to follow in my own (probably very confused) way:

 <xsl:for-each select="following::li[contains(./@class,'CStepBullet')][count(.|following-sibling::li[not(contains(./@class,'Bullet'))][1]/preceding-sibling::li[contains(./@class,'CStepBullet')]) = count(following-sibling::li[not(contains(./@class,'Bullet'))][1]/preceding-sibling::li[contains(./@class,'CStepBullet')])] ">

This currently produces no results in the output XML. I’m also sure it’s needlessly overengineered.

Thanks for looking, and in advance for any advice you can offer!

  • 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-06-03T16:10:00+00:00Added an answer on June 3, 2026 at 4:10 pm

    I. This XSLT 1.0 transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kFollowing" match="li[@class='kadov-p-CStepBullet']"
      use="generate-id(preceding-sibling::li[@class='kadov-p-CStep'][1])"/>
    
     <xsl:template match="node()|@*" name="identity">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="li[@class='kadov-p-CStep']">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    
        <xsl:variable name="vFollowing" select="key('kFollowing', generate-id())"/>
    
        <xsl:if test="$vFollowing">
          <ul>
            <xsl:apply-templates select="$vFollowing" mode="inGroup"/>
          </ul>
        </xsl:if>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="li[@class='kadov-p-CStepBullet']"/>
    
     <xsl:template match="li[@class='kadov-p-CStepBullet']" mode="inGroup">
      <xsl:call-template name="identity"/>
     </xsl:template>
     </xsl:stylesheet>
    

    when applied on the provided XML document:

    <div class="x-popup-text c3" id="POPUP172050488">
      <p>To add multiple balance adjustments:</p>
      <ol>
        <li class="kadov-p-CStep">
          <p class="Step">Check
          <span class="hcp1">Add to queue</span> at the bottom of the page.</p>
        </li>
        <li class="kadov-p-CStep">
          <p class="Step">At the top of the page, enter the
          <span class="hcp1">Account</span>. &#160;This is a three-part field:</p>
        </li>
        <li class="kadov-p-CStepBullet">
          <p class="StepBullet">In the first part, select the bank number &#160;from the drop-down list.</p>
        </li>
        <li class="kadov-p-CStepBullet">
          <p class="StepBullet">In the second part, select the application code from the drop-down list.</p>
        </li>
        <li class="kadov-p-CStepBullet">
          <p class="StepBullet">In the third part, enter the account number or click the account search button
          <img src="../mag_glass_blue_bkgrd.gif" x-maintain-ratio="TRUE" width="16" height="16" border="0" class="hcp2 c1" /> to find it.</p>
        </li>
      </ol>
      <ol start="3">
        <li class="kadov-p-CStep">
          <p class="Step">Enter the start date for the adjustment in the
          <span class="hcp1">From</span> field or click the calendar button
          <img src="../calendar.gif" x-maintain-ratio="TRUE" width="16" height="18" border="0" class="hcp2 c2" /> to select the date.</p>
        </li>
        <li class="kadov-p-CStep">
          <p class="Step">Enter the end date for the adjustment in the
          <span class="hcp1">Through</span> field or click the calendar button
          <img src="../calendar.gif" x-maintain-ratio="TRUE" width="16" height="18" border="0" class="hcp2 c2" /> to select the date.</p>
        </li>
      </ol>
      <p class="StepText">
      <span class="hcp1">Tip:</span> &#160;The Through date must be the same as or after the From date.</p>
      <ol start="5">
        <li class="kadov-p-CStep">
          <p class="Step">For each balance you want to adjust, do the following:</p>
        </li>
        <li class="kadov-p-CStepBullet">
          <p class="StepBullet">In the table at the bottom of the page, find the appropriate
          <span class="hcp1">Balance Type</span> for the adjustment.</p>
        </li>
        <li class="kadov-p-CStepBullet">
          <p class="StepBullet">Enter the
          <span class="hcp1">Amount</span> of the adjustment to the right of the balance type.</p>
        </li>
        <li class="kadov-p-CStepBullet">
          <p class="StepBullet">If you want the adjustment to appear on the customer's statement, check the
          <span class="hcp1">Print on Statements</span> checkbox that corresponds to the adjustment amount you entered.</p>
        </li>
      </ol>
      <ol start="6">
        <li class="kadov-p-CStep">
          <p class="Step">Click
          <span class="hcp1">Add</span>.</p>
        </li>
        <li class="kadov-p-CStep">
          <p class="Step">Repeat steps 2 through 7 for each additional adjustment you want to add.</p>
        </li>
        <li class="kadov-p-CStep">
          <p class="Step">Click the
          <span class="hcp1">View queue</span> link at the bottom of the page to enter the Work Queue and apply the adjustments.</p>
        </li>
      </ol>
    </div>
    

    produces the wanted, correct result:

    <div class="x-popup-text c3" id="POPUP172050488">
       <p>To add multiple balance adjustments:</p>
       <ol>
          <li class="kadov-p-CStep">
             <p class="Step">Check
          <span class="hcp1">Add to queue</span> at the bottom of the page.</p>
          </li>
          <li class="kadov-p-CStep">
             <p class="Step">At the top of the page, enter the
          <span class="hcp1">Account</span>.  This is a three-part field:</p>
             <ul>
                <li class="kadov-p-CStepBullet">
                   <p class="StepBullet">In the first part, select the bank number  from the drop-down list.</p>
                </li>
                <li class="kadov-p-CStepBullet">
                   <p class="StepBullet">In the second part, select the application code from the drop-down list.</p>
                </li>
                <li class="kadov-p-CStepBullet">
                   <p class="StepBullet">In the third part, enter the account number or click the account search button
          <img src="../mag_glass_blue_bkgrd.gif" x-maintain-ratio="TRUE" width="16"
                           height="16"
                           border="0"
                           class="hcp2 c1"/> to find it.</p>
                </li>
             </ul>
          </li>
       </ol>
       <ol start="3">
          <li class="kadov-p-CStep">
             <p class="Step">Enter the start date for the adjustment in the
          <span class="hcp1">From</span> field or click the calendar button
          <img src="../calendar.gif" x-maintain-ratio="TRUE" width="16" height="18" border="0"
                     class="hcp2 c2"/> to select the date.</p>
          </li>
          <li class="kadov-p-CStep">
             <p class="Step">Enter the end date for the adjustment in the
          <span class="hcp1">Through</span> field or click the calendar button
          <img src="../calendar.gif" x-maintain-ratio="TRUE" width="16" height="18" border="0"
                     class="hcp2 c2"/> to select the date.</p>
          </li>
       </ol>
       <p class="StepText">
          <span class="hcp1">Tip:</span>  The Through date must be the same as or after the From date.</p>
       <ol start="5">
          <li class="kadov-p-CStep">
             <p class="Step">For each balance you want to adjust, do the following:</p>
             <ul>
                <li class="kadov-p-CStepBullet">
                   <p class="StepBullet">In the table at the bottom of the page, find the appropriate
          <span class="hcp1">Balance Type</span> for the adjustment.</p>
                </li>
                <li class="kadov-p-CStepBullet">
                   <p class="StepBullet">Enter the
          <span class="hcp1">Amount</span> of the adjustment to the right of the balance type.</p>
                </li>
                <li class="kadov-p-CStepBullet">
                   <p class="StepBullet">If you want the adjustment to appear on the customer's statement, check the
          <span class="hcp1">Print on Statements</span> checkbox that corresponds to the adjustment amount you entered.</p>
                </li>
             </ul>
          </li>
       </ol>
       <ol start="6">
          <li class="kadov-p-CStep">
             <p class="Step">Click
          <span class="hcp1">Add</span>.</p>
          </li>
          <li class="kadov-p-CStep">
             <p class="Step">Repeat steps 2 through 7 for each additional adjustment you want to add.</p>
          </li>
          <li class="kadov-p-CStep">
             <p class="Step">Click the
          <span class="hcp1">View queue</span> link at the bottom of the page to enter the Work Queue and apply the adjustments.</p>
          </li>
       </ol>
    </div>
    

    Explanation:

    Appropriate use of a key to define any li[@class='kadov-p-CStepBullet'] as a function of its first preceding-sibling li[@class='kadov-p-CStep']. Also, proper use of modes.


    II. XSLT 2.0 solution:

    <xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="node()|@*" mode="#default inGroup">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*" mode="#current"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="ol[1]">
      <xsl:copy>
       <xsl:apply-templates select="@*"/>
       <xsl:for-each-group select="li"
                           group-starting-with="li[@class='kadov-p-CStep']">
         <xsl:apply-templates select="." mode="inGroup"/>
       </xsl:for-each-group>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="li[@class='kadov-p-CStep']">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    
        <xsl:if test="current-group()[2]">
          <ul>
            <xsl:apply-templates select="current-group()[position() gt 1]" mode="inGroup"/>
          </ul>
        </xsl:if>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="li[@class='kadov-p-CStepBullet']"/>
    </xsl:stylesheet>
    

    Explanation:

    Proper use of the xsl:for-each-group instruction with the attribute group-starting-with and the current-group() function. Also, appropriate use of modes, the built-ing modes #current and #default and a list of modes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm working with some pretty awesome HTML strings stored in our DB and
I have some pretty basic HTML/CSS that isn't working as I expect. Basically I
I'm still working my way through some pretty basic Actionscript programming (in Flex), and
I'm working on some middleware for rails, working with a pretty recent version: pfernand-2-mn:~
I'm working some code that inserts csv rows into an SQLite database using Python.
Working on some tweaks for a build script, I noticed that the output from
I working with some regular expression matching and I'm trying to figure out how
I'm trying to do some pretty simple stuff in Jython within Java. My Python
I'm pretty new at this iphone dev stuff and i'm working on some existing
I am working on a project which requires some pretty intricate JavaScript processing. This

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.