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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:47:07+00:00 2026-06-18T03:47:07+00:00

I am sure that my logic is not correct. However I am not sure

  • 0

I am sure that my logic is not correct. However I am not sure how to resolve this without multiple for-each tests.

Perhaps a for-each is not the correct way to go? I would appreciate any advice. Additinally I am using XSLT 1.0 in case that is necessary information.

Here is the XML that I am using:

<?xml version="1.0" encoding="utf-8"?>
<FIGURES>
    <FIGURE>
        <TITLE>Title 1</TITLE>
        <DESC>Description 1</DESC>
        <CONTENT>Content 1</CONTENT>
    </FIGURE>
    <FIGURE>
        <TITLE>Title 2</TITLE>
        <DESC>Description 2</DESC>
        <CONTENT>Content 2</CONTENT>
    </FIGURE>
    <FIGURE>
        <TITLE>Title 2</TITLE>
        <DESC>Description 2</DESC>
        <CONTENT>Content 2</CONTENT>
    </FIGURE>
</FIGURES>

Here is the XSLT that I am trying:

<xsl:template match="/">
  <div class="container">
    <ul class="list">

      <xsl:for-each select="//FIGURE">

        <li>
          <a href="#section-{position()}"><h3><xsl:value-of select="TITLE" /></h3></a>
          <p><xsl:value-of select="DESC" /></p>
        </li>

        <div class="content">
          <div id="section-{position()}">
            <xsl:value-of select="CONTENT" />
          </div>
        </div>                           

      </xsl:for-each>  

    </ul>    
  </div>

</xsl:template>

Here is the HTML that I want but am not getting:

<div class="container">
  <ul class="list">
    <li>
      <a href="#section-1"><h3>Title 1</h3></a>
      <p>Description 1</p>
    </li>
    <li>
      <a href="#section-2"><h3>Title 2</h3></a>
      <p>Description 2</p>
    </li>   
    <li>
      <a href="#section-3"><h3>Title 3</h3></a>
      <p>Description 3</p>
    </li>
  </ul>
  <div class="content">
    <div id="section-1">
      <p>Content 1</p>
    </div>
    <div id="section-1">
      <p>Content 2</p>
    </div>  
    <div id="section-1">
      <p>Content 2</p>
    </div>          
  </div>
</div>

Here is the HTML that I get, but do not want:

<div class="container">
  <ul class="list">
    <li>
      <a href="#section-1"><h3>Title 1</h3></a>
      <p>Description 1</p>
    </li>
   <div class="content">
     <div id="section-1">Content 1</div>
   </div>
   <li>
     <a href="#section-2"><h3>Title 2</h3></a>
     <p>Description 2</p>
   </li>
   <div class="content">
     <div id="section-2">Content 2</div>
   </div>
   <li>
     <a href="#section-3"><h3>Title 2</h3></a>
     <p>Description 2</p>
   </li>
   <div class="content">
     <div id="section-3">Content 2</div>
   </div>
 </ul>
</div>

EDIT Using Sean’s example I figured it out. I was just missing the select attribute on the tags.

<xsl:template match="/">
  <div class="container">
    <xsl:apply-templates />
  </div>
</xsl:template>

<xsl:template match="FIGURES">
  <ul class="list">
    <xsl:apply-templates select="FIGURE" mode="titles" />
  </ul>  
  <div class="content">
    <xsl:apply-templates select="FIGURE" mode="content" />
  </div>
</xsl:template>

<xsl:template match="FIGURE" mode="titles">
  <li>
    <a href="#section-{position()}">
      <h3><xsl:value-of select="TITLE" /></h3>
    </a>
    <p><xsl:value-of select="DESC" /></p>
  </li>
</xsl:template>

<xsl:template match="FIGURE" mode="content">
  <div id="section-{position()}">
    <p><xsl:value-of select="CONTENT" /></p>
  </div>
</xsl:template>
  • 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-18T03:47:10+00:00Added an answer on June 18, 2026 at 3:47 am

    This XSLT 1.0 stylesheet…*

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes" doctype-system="about:legacy-compat" encoding="UTF-8" />
    <xsl:strip-space elements="*" />
    
    <xsl:template match="/">
     <html>
       <body>
         <div class="container">
           <xsl:apply-templates />
         </div>
       </body>
     </html>
    </xsl:template>
    
    <xsl:template match="FIGURES">
      <ul class="list">
        <xsl:apply-templates mode="titles" />
      </ul>  
      <div class="content">
        <xsl:apply-templates mode="content" />
      </div>
    </xsl:template>
    
    <xsl:template match="FIGURE" mode="titles">
      <li>
        <a href="#section-{position()}">
          <h3><xsl:value-of select="TITLE" /></h3>
        </a>
        <p><xsl:value-of select="DESC" /></p>
      </li>
    </xsl:template>
    
    <xsl:template match="FIGURE" mode="content">
      <div id="section-{position()}">
        <p><xsl:value-of select="CONTENT" /></p>
      </div>
    </xsl:template>
    
    </xsl:stylesheet>
    

    …when applied to the referenced input document, will yield…

    <!DOCTYPE html SYSTEM "about:legacy-compat">
    <html>
      <body>
        <div class="container">
          <ul class="list">
            <li><a href="#section-1"><h3>Title 1</h3></a><p>Description 1</p>
            </li>
            <li><a href="#section-2"><h3>Title 2</h3></a><p>Description 2</p>
            </li>
            <li><a href="#section-3"><h3>Title 2</h3></a><p>Description 2</p>
            </li>
          </ul>
          <div class="content">
            <div id="section-1">
              <p>Content 1</p>
            </div>
            <div id="section-2">
              <p>Content 2</p>
            </div>
            <div id="section-3">
              <p>Content 2</p>
            </div>
          </div>
        </div>
      </body>
    </html>
    

    Update

    If you are not using xsl:strip-space (you should, as I gave this to you in the solution), or if for some reason, you have other nodes interspersed between the FIGURE elements, then this style-sheet will give you a more robust solution…

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes" doctype-system="about:legacy-compat" encoding="UTF-8" />
    <xsl:strip-space elements="*" />
    
    <xsl:template match="/">
     <html>
       <body>
         <div class="container">
           <xsl:apply-templates />
         </div>
       </body>
     </html>
    </xsl:template>
    
    <xsl:template match="FIGURES">
      <ul class="list">
        <xsl:apply-templates mode="titles" />
      </ul>  
      <div class="content">
        <xsl:apply-templates mode="content" />
      </div>
    </xsl:template>
    
    <xsl:template match="FIGURE" mode="titles">
      <li>
        <a href="#section-{count(preceding-sibling::FIGURE)+1}">
          <h3><xsl:value-of select="TITLE" /></h3>
        </a>
        <p><xsl:value-of select="DESC" /></p>
      </li>
    </xsl:template>
    
    <xsl:template match="FIGURE" mode="content">
      <div id="section-{count(preceding-sibling::FIGURE)+1}">
        <p><xsl:value-of select="CONTENT" /></p>
      </div>
    </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'm not even sure that Postgres' HStore data type can contain nested hashes, and
I'm not sure that title is worded very well, but not sure how else
I'm not sure that title conveys my meaning, please change it if you can
I am sure that this kind of questions must have been asked before, but
Im not sure that its possible to do what I want to accomplish. I
I am writing web application I am not sure what is the correct response
This question could be subjective. I'm not sure if it belongs here or on
Ugh - not sure why I'm having so much trouble with this. Writing a
Not sure what I am doing wrong here. I am hoping that it is
I am sure that I am simply overlooking something, and I spent a few

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.