Two-column list using XSLT

I am seeking assistance with xsl transformation. The xml generated by SharePoint Server control is as follows:

<rows>
    <row>A</row>
    <row>B</row>
    <row>C</row>
    <row>D</row>
    <row>E</row>
    <row>F</row>
    <row>G</row>
    <row>H</row>
</rows>

The required transformation of the above xml is as shown below:

  <==  A-----------B  ==> An li sliding back and forth with the help of a slider plugin
       C-----------D
       E-----------F
       G-----------H

JUST LIKE THIS:
(source: imagesup.net)

The necessary HTML format for the slider plugin to function correctly is as follows:

<div class="content-carousel">
<!-- start Basic Jquery Slider -->
        <ul class="bjqs">
          <li>
              <div class="content-left">
               <h4>A</h4>
               </div>
              <div class="content-right">
               <h4>B</h4>
               </div>
          </li>
        <li>
              <div class="content-left">
               <h4>C</h4>
               </div>
              <div class="content-right">
               <h4>D</h4>
               </div>
          </li>
          .
          .
        </ul>
</div>

Here is the actual raw XML file: https://gist.github.com/4380967

Check out the bjqs slider plugin requirement here:
(source: imagesup.net)

CURRENT PROGRESS: Although I have managed to achieve a two-column layout, it involves using table rows which generates unnecessary markup that is not suitable for the slider plugin. Here's what I have done for each row:

 <xsl:if test="$CurPos = 1 ">
    <xsl:text disable-output-escaping="yes">&lt;div&gt;&lt;table&gt;</xsl:text>
  </xsl:if>
  <xsl:if test="$CurPos mod 2 = 1">
    <xsl:text disable-output-escaping="yes">&lt;tr&gt;</xsl:text>
  </xsl:if> 
 
<li>
  <td width="50%" valign="top">
    <table width="90%">
      <tr height="35px" min-height="35px" valign="top">
        <td>
          <span>
            <xsl:if test="string-length($SafeImageUrl) != 0">
              <div class="image-area-left">
                <a href="{$SafeLinkUrl}" target="{$LinkTarget}">
                  <img class="image" src="{$SafeImageUrl}" alt="{@ImageUrlAltText}" />
                </a>
              </div>
            </xsl:if>
            
            <H3>
                <a href="{$SafeLinkUrl}"> <xsl:value-of select="@Title"/> </a>
            </H3>
            <div class="newsgist"><xsl:value-of select="substring(@Comments,0,200)"/>
                <xsl:if test="string-length(@Comments) &gt; 200">…</xsl:if>         <a href="{$SafeLinkUrl}"> Details…</a>  
            </div>
          </span> 
        </td>
      </tr>
 
    </table>
  </td></li>
 
  <xsl:if test="$CurPos mod 2 = 0">
    <xsl:text disable-output-escaping="yes">&lt;/tr&gt;</xsl:text>
  </xsl:if>
  <xsl:if test="$CurPos = $LastRow ">
    <xsl:text disable-output-escaping="yes">&lt;/table&gt;&lt;/div&gt;</xsl:text>

Answer №1

Application:

<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:template match="/*">
     <div class="content-carousel">
     <ul class="bjqs">
      <xsl:apply-templates select="*[position() mod 2 =1]"/>
     </ul>
   </div>
 </xsl:template>

 <xsl:template match="row">
   <li>
     <div class="content-left">
        <h4><xsl:value-of select="."/></h4>
     </div>
       <div class="content-right">
         <h4><xsl:value-of select="following-sibling::*[1]"/></h4>
       </div>
  </li>
 </xsl:template>
</xsl:stylesheet>

Upon applying this transformation to the given XML document:

<rows>
    <row>A</row>
    <row>B</row>
    <row>C</row>
    <row>D</row>
    <row>E</row>
    <row>F</row>
    <row>G</row>
    <row>H</row>
</rows>

The desired output is obtained:

<div class="content-carousel">
   <ul class="bjqs">
      <li>
         <div class="content-left">
            <h4>A</h4>
         </div>
         <div class="content-right">
            <h4>B</h4>
         </div>
      </li>
      <li>
         <div class="content-left">
            <h4>C</h4>
         </div>
         <div class="content-right">
            <h4>D</h4>
         </div>
      </li>
      <li>
         <div class="content-left">
            <h4>E</h4>
         </div>
         <div class="content-right">
            <h4>F</h4>
         </div>
      </li>
      <li>
         <div class="content-left">
            <h4>G</h4>
         </div>
         <div class="content-right">
            <h4>H</h4>
         </div>
      </li>
   </ul>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Integrate SVG into the dropdown menu without duplicating the SVG element

I have an SVG of a right arrow: <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"> <path d="M0 0h24v24H0V0z" fill="none"/> ...

Here's a way to run JavaScript code from a <script> tag included in an AJAX response

Currently, I am making a jQuery GET request in this format: $.get($(this).attr("href"), $(this).serialize(), null, "script"); I'm expecting the response to be enclosed in script tags. I know that the browser won't run the response if it contai ...

What is the best way to cut out a portion of a div using CSS?

I have a scaled down version of my project, but it's not quite what I need. I would like the green div to have some transparency so that the content behind both divs is visible (there is none in the example, but there is in my actual project). However ...

Internet Explorer experiences performance issues when a table containing over 500 rows is being utilized

Can anyone offer advice on speeding up the display of large tables with 500+ rows in Internet Explorer? Here is my current approach: The MySQL query result includes 500+ rows, which I then loop through using a while loop to display: echo "<tr class=& ...

Creating a unique handle for resizing in jQuery UI's resizable()

Take a look at the JSFiddle link provided. I've been able to successfully use the resizeable() function without any issues when using the default handler. However, when I try to specify a custom handler, the box doesn't resize as expected - even ...

Navbar active class not updating on jQuery page scroll

My one-page website has a fixed navbar that I want to change its active status when scrolling down to specific div positions. Even though I tried using jQuery, the code doesn't seem to work as intended. Here is the snippet: // SMOOTH SCROLLING PAGES ...

Form featuring many submission buttons

Can anyone help me identify which submit button has been clicked on a form with multiple buttons? $("#my_form").on("submit", function(event) { event.preventDefault(); var form_action = $(this).attr("action"); var form_data = $(this).seri ...

Creating multiple unique custom attributes for a specialized HTML element

Creating getter/setter methods for a custom attribute on a custom HTML element is quite simple: customElements.define('custom-el', class extends HTMLElement { static get observedAttributes() { return ['customAttr'] ...

The collapsing menu is malfunctioning due to duplicate selectors

Although I have been learning HTML, CSS and jQuery, one area that always trips me up is selectors. Currently struggling with redundant selectors. I am attempting to customize the ul and li elements after collapsing the li, however, the selector doesn&apos ...

Guide to creating a nested list using the jQuery :header selector

Here is the structure of my html: <h1 id="header1">H1</h1> <p>Lorem ipsum</p> <h2 id="header2">H2</h2> <p>lorem ipsum</p> <h2 id="header3">H2</h2> <p>lorem upsum</p ...

Validation in JQuery Mobile is crucial for ensuring that user input is correct before submitting a

Trying to create a login page using JQuery Mobile, I implemented validation with the jQuery validation plugin and AJAX to post the data to a PHP server code if validation is successful. However, instead of functioning as intended, the code redirects back t ...

Creating a circular array of raycast directions with HTML Canvas 2D

I'm currently working on implementing raycasting in typescript with HTML Canvas 2D based on the tutorial from this video: https://youtu.be/TOEi6T2mtHo. However, I've encountered an issue where the rays being cast consistently point in a single di ...

Tips on utilizing Ajax for updating the RenderBody() segment

Can anyone help me understand why my Ajax.ActionLink menu item is calling JavaScript twice when I try to use it for the second time? I simply want to update the RenderBody() after clicking on a menu item. _Layout.cshtml: ... <body> <div i ...

Highlight.js is not able to display HTML code

It's strange, I can't seem to get the HTML code to display correctly. This is my HTML: <head> <link rel="stylesheet" href="/path/to/default.css"> <script src="/path/to/highlight.pack.js"></script> <script& ...

What steps should be taken to incorporate a user input space similar to the one found in the Wordpress new post section

I am looking to incorporate a user input section on my website similar to the one found in WordPress for creating new posts. I would like this area to have all of the same tools available, such as adding hyperlinks, bolding text, and uploading images. Ca ...

React beautiful dnd and Material UI list encountering compatibility problem

I recently encountered an issue while using react beautiful dnd to create a rearrangeable Material UI List. Everything was working correctly, except for the ListItemSecondaryAction within the list. When dragging a list item, the ListItemText and ListItemIc ...

Avoid making the check mark disappear in an SVG animation

After perfecting my CSS animation, I have the circle looping around to complete its shape while a check mark fills in the middle with a slight delay. Once both shapes are completed simultaneously, the check mark disappears. The reason for the disappearing ...

Ensuring JS consistently monitors changes in value

Is there an equivalent of (void update) in Unity that is called every frame in Web Development (using JavaScript)? "I want it to continuously check if certain values have changed and then update them accordingly." let governmentprice = parseFloat(select ...

The CSS method to conceal the initial list item is proving ineffective

I'm having an issue with my WordPress theme where I want to hide only the first li element but it's hiding all of them. Here is the HTML code I'm using: <div class="nav"> <ul class="nav-tabs nav-justified"> <li class="activ ...

Utilize data attributes in VueJS to dynamically style elements

Is there a way to utilize the data() values within the <style>..</style> section? I have experimented with different combinations (using/omitting this, with/without {{brackets}}, etc.) but haven't been successful. Interestingly, when I man ...