How to display alternately rows design using XSLt file in C#?

I have project used a xslt file to display records using below code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes" />
  <xsl:param name="BasePath" select="/" />
  <xsl:param name="OffersPerPage" select="4" />
  <xsl:template match="/" xml:space="default">
<div class="offers_section">
<script>
  $(document).ready(function() {
  $(".offers_page").hide();
  $("#OfferPage1").show();
  });
  function OffersPageChange(CurrentPage, NewPage)
  {
   $("#OfferPage" + CurrentPage).hide();
$("#OfferPage" + NewPage).show();
$("$offers_section").focus();
return false;
  }
</script>
<xsl:choose>
  <xsl:when test="count(//Offers/Offer) &gt; 0">

  <xsl:for-each select="//Offers/Offer[(position()) mod $OffersPerPage = 1 or position = 1]">
    <xsl:variable name="page" select="position()" />
    <xsl:variable name="lastpage" select="last()" />

    <div class="offers_page"><xsl:attribute name="id">OfferPage<xsl:value-of select="$page" /></xsl:attribute>
      <div class="offers_paging">
        <xsl:if test="$page &gt; 1">
        <a href="#"><xsl:attribute name="onclick">return OffersPageChange(<xsl:value-of select="$page" />, <xsl:value-of select="$page - 1" />)</xsl:attribute>&lt; Previous</a>
        </xsl:if>

        <xsl:if test="$page &lt; $lastpage">
        <a href="#"><xsl:attribute name="onclick">return OffersPageChange(<xsl:value-of select="$page" />, <xsl:value-of select="$page + 1" />)</xsl:attribute>Next &gt;</a>
        </xsl:if>
        <br /><br />

        <xsl:if test="$lastpage != 1">
          <xsl:for-each select="//Offers/Offer">
            <xsl:if test="(position() - 1) mod $OffersPerPage = 0">
              <a href="#"><xsl:attribute name="class"><xsl:choose><xsl:when test="(position() - 1) div $OffersPerPage + 1 = $page">offers_page_number_active</xsl:when><xsl:otherwise>offers_page_number</xsl:otherwise></xsl:choose></xsl:attribute><xsl:attribute name="onclick">return OffersPageChange(<xsl:value-of select="$page" />, <xsl:value-of select="(position() - 1) div $OffersPerPage + 1" />)</xsl:attribute><xsl:value-of select="(position() - 1) div $OffersPerPage + 1" /></a>
            </xsl:if>
          </xsl:for-each>
          <br /><br />
        </xsl:if>
      </div>

      <xsl:for-each select=". | following-sibling::Offer[(position()) &lt; $OffersPerPage]" >
        <div class="offers_offer">
          <h2><xsl:value-of select="Partner" /></h2>

          <xsl:if test="ImageSource != ''">
          <div class="offers_image_container">
            <div class="offers_image">
              <img width="100%"><xsl:attribute name="src"><xsl:value-of select="$BasePath" />portals/7/<xsl:value-of select="ImageSource" /></xsl:attribute></img>
            </div>
            <div class="offers_image_overlay">
              <img width="100%" height="33" alt=""><xsl:attribute name="src"><xsl:value-of select="$BasePath" />portals/_default/skins/onlyin/images/offer%20top%20swoop.png</xsl:attribute></img>
              <img width="100%" height="126" style="position:absolute;bottom:0;left:0;right:0;" alt=""><xsl:attribute name="src"><xsl:value-of select="$BasePath" />portals/_default/skins/onlyin/images/offer%20bottom%20swoop.png</xsl:attribute></img>
            </div>
          </div>
          </xsl:if>

          <xsl:if test="Description != ''">
          <div class="offers_description">
            <xsl:value-of select="Description" /><br />
          </div>
          </xsl:if>

          <xsl:if test="LegalInformation != '' and LegalOnOfferPage = 'True'">
          <div class="offers_legal">
            <xsl:value-of select="LegalInformation" /><br />
          </div>
          </xsl:if>

          <xsl:if test="Facebook != '' or Twitter != ''">
          <div class="offers_social_media">
            Follow us on:<br />
            <div class="social_media_links">
              <xsl:if test="Facebook != ''">
              <a class="facebook_logo" style="float:none;" target="_blank" title="Facebook"><xsl:attribute name="href"><xsl:value-of select="Facebook" /></xsl:attribute></a>
              </xsl:if>
              <xsl:if test="Twitter != ''">
              <a class="twitter_logo" style="float:none;" target="_blank" title="Twitter"><xsl:attribute name="href">https://www.twitter.com/<xsl:value-of select="Twitter" /></xsl:attribute></a>
              </xsl:if>
            </div>
          </div>
          </xsl:if>

          <xsl:if test="UrlText != ''">
          <div class="offers_url">
          <a target="_blank"><xsl:attribute name="onclick"><xsl:value-of select="onclick" /></xsl:attribute><xsl:attribute name="href"><xsl:value-of select="Url" /></xsl:attribute><xsl:value-of select="UrlText" /></a>
          </div>
          </xsl:if>

          <xsl:if test="Email != ''">
          <div class="offers_email">
          Email: <a> <xsl:attribute name="onclick"><xsl:value-of select="Emailonclick" /></xsl:attribute><xsl:attribute name="href">mailto:<xsl:value-of select="Email" /></xsl:attribute><xsl:value-of select="Email" /></a>
          </div>
          </xsl:if>

          <xsl:if test="Phone != ''">
          <div class="offers_phone">
          Tel no: <strong><xsl:value-of select="Phone" /></strong>
          </div>
          </xsl:if>
        </div>
      </xsl:for-each>
      <xsl:if test="$lastpage &gt; 1">

      <div class="offers_paging">
        <xsl:if test="$lastpage != 1">
          <xsl:for-each select="//Offers/Offer">
            <xsl:if test="(position() - 1) mod $OffersPerPage = 0">
              <a href="#"><xsl:attribute name="class"><xsl:choose><xsl:when test="(position() - 1) div $OffersPerPage + 1 = $page">offers_page_number_active</xsl:when><xsl:otherwise>offers_page_number</xsl:otherwise></xsl:choose></xsl:attribute><xsl:attribute name="onclick">return OffersPageChange(<xsl:value-of select="$page" />, <xsl:value-of select="(position() - 1) div $OffersPerPage + 1" />)</xsl:attribute><xsl:value-of select="(position() - 1) div $OffersPerPage + 1" /></a>
            </xsl:if>
          </xsl:for-each>
          <br /><br />
        </xsl:if>

        <xsl:if test="$page &gt; 1">
        <a href="#"><xsl:attribute name="onclick">return OffersPageChange(<xsl:value-of select="$page" />, <xsl:value-of select="$page - 1" />)</xsl:attribute>&lt; Previous</a>
        </xsl:if>

        <xsl:if test="$page &lt; $lastpage">
        <a href="#"><xsl:attribute name="onclick">return OffersPageChange(<xsl:value-of select="$page" />, <xsl:value-of select="$page + 1" />)</xsl:attribute>Next &gt;</a>
        </xsl:if>
      </div>
      </xsl:if>
    </div>
  </xsl:for-each>
  </xsl:when>
  <xsl:otherwise>
    <div class="offers_not_available">
      Sorry, no offers are currently available in this category
    </div>
  </xsl:otherwise>
</xsl:choose>
</div>

Code behind code is:

void Load_Category(int CategoryId)
    {
        string skinPath = PortalSettings.ActiveTab.SkinPath;

        XDocument XDocOffers = new XDocument(new XElement("Offers"));
        SqlDataProvider provider = new SqlDataProvider();
        SqlConnection SQLConnection = new SqlConnection(provider.ConnectionString);
        SQLConnection.Open();

        SqlConnection SQLConnectionAnswers = new SqlConnection(provider.ConnectionString);
        SQLConnectionAnswers.Open();

        SqlCommand sqlComm = new SqlCommand("OffersGetOffersByCategory", SQLConnection);
        sqlComm.CommandType = CommandType.StoredProcedure;

        sqlComm.Parameters.Add(new SqlParameter("@CategoryId", SqlDbType.Int)).Value = CategoryId;

        SqlDataReader OffersReader = sqlComm.ExecuteReader();

        string OfferId;
        string Partner;
        string Description;
        string ImageSource;
        string Url;
        string UrlText;
        string Email;
        string Phone;
        string LegalInformation;
        string Facebook;
        string Twitter;
        string LegalOnOfferPage;
        string onclick;
        string Emailonclick;
        while (OffersReader.Read())
        {
            OfferId = OffersReader["OfferId"].ToString();
            Partner = OffersReader["Partner"].ToString();
            Description = OffersReader["Description"].ToString();
            ImageSource = OffersReader["ImageSource"].ToString();
            Url = OffersReader["Url"].ToString();
            UrlText = OffersReader["UrlText"].ToString();
            Email = OffersReader["Email"].ToString();
            Phone = OffersReader["Phone"].ToString();
            LegalInformation = OffersReader["LegalInformation"].ToString();
            Facebook = OffersReader["Facebook"].ToString();
            Twitter = OffersReader["Twitter"].ToString();
            LegalOnOfferPage = OffersReader["LegalOnOfferPage"].ToString();
            onclick = "_gaq.push(['_trackEvent', 'Book Now', 'click', '" + Partner + "']);";
            Emailonclick = "_gaq.push(['_trackEvent', 'Email', 'click', '" + Email + "']);";
            XElement NextOffer =
              new XElement("Offer",
                new XElement("OfferId", OfferId),
                new XElement("Partner", Partner),
                new XElement("Description", Description),
                new XElement("ImageSource", ImageSource),
                new XElement("Url", Url),
                new XElement("UrlText", UrlText),
                new XElement("Email", Email),
                new XElement("Phone", Phone),
                new XElement("LegalInformation", LegalInformation),
                new XElement("Facebook", Facebook),
                new XElement("Twitter", Twitter),
                new XElement("LegalOnOfferPage", LegalOnOfferPage),
                new XElement("onclick", onclick),
                new XElement("Emailonclick", Emailonclick)
              );

            XDocOffers.Element("Offers").Add(NextOffer);
        }

        OffersReader.Close();
        SQLConnection.Close();

        string XSLTFile = Server.MapPath(skinPath + "xslt/offers.xslt");
        if (File.Exists(XSLTFile))
        {
            StringWriter XSLTOutput = new StringWriter();
            XmlWriter XMLOutput = XmlWriter.Create(XSLTOutput);

            // Load the style sheet.
            XslCompiledTransform xslt = new XslCompiledTransform();
            xslt.Load(XSLTFile);

            XsltArgumentList ArgumentsQA = new XsltArgumentList();

            if (Settings.ContainsKey("OffersPerPage"))
            {
                ArgumentsQA.AddParam("OffersPerPage", "", Settings["OffersPerPage"].ToString());
            }
            else
            {
                ArgumentsQA.AddParam("OffersPerPage", "", "4");
            }

            ArgumentsQA.AddParam("BasePath", "", "/");

            // Execute the transform and output the results to a writer.
            xslt.Transform(XDocOffers.CreateReader(), ArgumentsQA, XMLOutput);

            //Output.Controls.Add(new LiteralControl(XSLTOutput.ToString().Replace("&amp;", "&")));
            Output.Controls.Add(new LiteralControl(HttpUtility.HtmlDecode(XSLTOutput.ToString())));
        }
        else
        {
            Output.Controls.Add(new LiteralControl("Cannot find XSLT file"));
        }
    }

Problem is:

Now display the detail in some different format for alternate row. currently, every offer has image in left side and description in right, for alternate row now i want to display description in left and image in right, i have never used xslt file before, can anyone please help... or suggest me how can achieve this.

waiting for your helpful answers..

Answers


i have solved out this problem.. Here is the solution, we didn't need to changes anything in c# code(code behind), we have just changed the xslt file t do this, as xslt file number of inbuilt functions to do.

I have used mod as below:

 <xsl:for-each select=". | following-sibling::Offer[(position()) &lt; $OffersPerPage]" >
<xsl:choose>
         <xsl:when test="position() mod 2 = 1">
             data 1
         </xsl:when>
         <xsl:otherwise>
             data 2
         </xsl:otherwise>
   </xsl:choose>
 </xsl:for-each>

That's all.....


Need Your Help

How do I only show pictures in PHP once they're done uploading?

php

I'm uploading an image using WinSCP, which gets sent to a web server using PHP.

GMAIL: This message has been modified to fit your screen. Tap here to show original

html email gmail html-email

I made fixed email template. But When I trying to test it on mobile devices in gmail (and it is happening only in gmail) it is break my layout (looks like it make my layout to fit device width like...