Solved

inserting table row every tens rows XSLT

Posted on 2011-03-08
9
461 Views
Last Modified: 2012-05-11
Hi,

I have an XSLT file that displays my XML feed in a table format.
What I need to do is every 10 records insert a row with some default information.

I can attach my XSLT if it would make it easier

Thanks
0
Comment
Question by:al4ddin
  • 5
  • 4
9 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35070730
Please attach teh XSLT

IF what you want to do is "have records in a cell, and ten cells per row", then you should not do this in a procedural way
I will show you how to do it if you can show source XML and the XSLT you have so far
0
 

Author Comment

by:al4ddin
ID: 35070893

<xsl:template match="/">
    <xsl:apply-templates select="Offers"/>
  </xsl:template>
  <xsl:template match="Offers">
    <xsl:choose>
      <xsl:when test="normalize-space($county) and normalize-space($county) != 'n/a' and normalize-space($county) != 'All'">
        <xsl:apply-templates mode="county_only" select="county[contains(normalize-space($county), ./CID)]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="county"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="county">
    <xsl:choose>
      <xsl:when test="normalize-space($city) and normalize-space($city) != 'n/a'">
        <xsl:choose>
          <xsl:when test="normalize-space($freight) and normalize-space($freight) != 'n/a'">
            <xsl:call-template name="county_table">
              <xsl:with-param name="records" select="descendant::record"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="county_table">
              <xsl:with-param name="records" select="descendant::record"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:when test="normalize-space($freight) and normalize-space($freight) != 'n/a'">
        <xsl:call-template name="county_table">
          <xsl:with-param name="records" select="descendant::record"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="county_table">
          <xsl:with-param name="records" select="descendant::record"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="county" mode="county_only">
    <xsl:call-template name="county_table">
      <xsl:with-param name="records" select="descendant::record"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template name="county_table">
    <xsl:param name="records"/>
    <xsl:choose>
      <xsl:when test="count($records) &gt; 0">
        <xsl:element name="a">
          <xsl:attribute name="name">
            <xsl:value-of select="CID"/>
          </xsl:attribute>
          <xsl:attribute name="href">#</xsl:attribute>
          <xsl:comment>anchor text</xsl:comment>
        </xsl:element>
        <h2>
          <xsl:call-template name="county_map">
            <xsl:with-param name="cid" select="CID"/>
          </xsl:call-template>
        </h2>
        <div class="template_content_wrapper clear">
          <div class="table_wrapper sorting_table">
            <table>
              <thead>
                <tr class="no-background">
                  <th>
                    <span class="sorting_header_text">
                      <xsl:value-of select="$sf_destination"/>
                    </span>
                    <xsl:choose>
                      <xsl:when test="$sort_order='ascending' and $sort='DestFrom'">
                        <a href="?sort=DestFrom&amp;sort_order=descending">
                          <img alt="Sort ascending selected" src="{$uparrow-on}"/>
                          <img alt="Sort descending" src="{$downarrow}"/>
                        </a>
                      </xsl:when>
                      <xsl:when test="$sort_order='descending' and $sort='DestFrom'">
                        <a href="?sort=DestFrom&amp;sort_order=ascending">
                          <img alt="Sort ascending" src="{$uparrow}"/>
                          <img alt="Sort descending selected" src="{$downarrow-on}"/>
                        </a>
                      </xsl:when>
                      <xsl:otherwise>
                        <a href="?sort=DestFrom&amp;sort_order=ascending">
                          <img alt="Sort ascending" src="{$uparrow}"/>
                          <img alt="Sort descending" src="{$downarrow}"/>
                        </a>
                      </xsl:otherwise>
                    </xsl:choose>
                  </th>
                  <th>
                    <span class="sorting_header_text">
                      <xsl:value-of select="$sf_destinationTo"/>
                    </span>
                    <xsl:choose>
                      <xsl:when test="$sort_order='ascending' and $sort='DestTo'">
                        <a href="?sort=DestTo&amp;sort_order=descending">
                          <img alt="Sort ascending selected" src="{$uparrow-on}"/>
                          <img alt="Sort descending" src="{$downarrow}"/>
                        </a>
                      </xsl:when>
                      <xsl:when test="$sort_order='descending' and $sort='DestTo'">
                        <a href="?sort=DestTo&amp;sort_order=ascending">
                          <img alt="Sort ascending" src="{$uparrow}"/>
                          <img alt="Sort descending selected" src="{$downarrow-on}"/>
                        </a>
                      </xsl:when>
                      <xsl:otherwise>
                        <a href="?county={CID}&amp;sort=DestTo&amp;sort_order=ascending">
                          <img alt="Sort ascending" src="{$uparrow}"/>
                          <img alt="Sort descending" src="{$downarrow}"/>
                        </a>
                      </xsl:otherwise>
                    </xsl:choose>
                  </th>
                  <th>
                    <span class="sorting_header_text">
                      <xsl:value-of select="$sf_price_from"/>
                    </span>
                    <xsl:choose>
                      <xsl:when test="$sort_order='ascending' and $sort='Price'">
                        <a href="?county={CID}&amp;sort=Price&amp;sort_order=descending">
                          <img alt="Sort ascending selected" src="{$uparrow-on}"/>
                          <img alt="Sort descending" src="{$downarrow}"/>
                        </a>
                      </xsl:when>
                      <xsl:when test="$sort_order='descending' and $sort='Price'">
                        <a href="?county={CID}&amp;sort=Price&amp;sort_order=ascending">
                          <img alt="Sort ascending" src="{$uparrow}"/>
                          <img alt="Sort descending selected" src="{$downarrow-on}"/>
                        </a>
                      </xsl:when>
                      <xsl:otherwise>
                        <a href="?county={CID}&amp;sort=Price&amp;sort_order=ascending">
                          <img alt="Sort ascending" src="{$uparrow}"/>
                          <img alt="Sort descending" src="{$downarrow}"/>
                        </a>
                      </xsl:otherwise>
                    </xsl:choose>
                  </th>
                  <th>
                    <xsl:comment>anchor text</xsl:comment>
                  </th>
                </tr>
              </thead>
              <tbody>
                <xsl:for-each select="$records">
                  <!-- Sort by price in descending/asceding-->
                  <xsl:sort data-type="{$data-type}" order="{$sort_order}" select="*[name(.)=$sort]"/>
                  <!-- <xsl:sort order="{$sort_order}" select="*[name(.)=$sort]"/> -->
                  <xsl:call-template name="record"/>
                </xsl:for-each>
              </tbody>
            </table>
          </div>
          <div class="wowRSSLinks clearfix">
            <div class="rss">
              <a href="{$page_url_rss}?rss=true&amp;county={CID}" onclick="dcsMultiTrack('DCS.dcsuri', '{$rdeXmlID}', 'WT.ti', 'Page {$feed_title}', 'DCSext.button_placement',dcsPageURL, 'DCSext.lnk_bt','RSS Feed CID={CID}');">
                <xsl:value-of select="concat($sf_prefix_rss_link, ' ')"/>
                <strong>
                  <xsl:call-template name="county_map">
                    <xsl:with-param name="cid" select="CID"/>
                  </xsl:call-template>
                </strong>
                <xsl:value-of select="concat(' ', $sf_conjuncion_rss_link, ' ')"/>
                <span class="rss_icon">RSS</span>
              </a>
            </div>
            <!--                         <ul>
                            <li><a href="#">Google<span></span></a></li>
                            <li><a href="#">MSN<span></span></a></li>
                            <li><a href="#">Yahoo<span></span></a></li>
                            </ul> -->
          </div>
          <!-- close wowrss-->
        </div>
        <!-- close table -->
      </xsl:when>
      <xsl:otherwise>
        <!-- TODO
                <p>
                    <xsl:value-of select="$sf_no_result"/>
                </p> -->
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="record">
    <tr>
      <td>
        <xsl:value-of select="DestFrom"/>
      </td>
      <!-- Destinatin To -->
      <td>
        <xsl:value-of select="DestTo"/>
      </td>
      <!-- End -->
      <td>
        <xsl:value-of select="$sf_price_currency"/>
        <xsl:value-of select="Price"/>
      </td>
      <td>
        <xsl:choose>
          <xsl:when test="CallToAction='phone'">
            <div>
              <a href="#">
                <xsl:element name="img">
                  <xsl:attribute name="src">call.png</xsl:attribute>
                  <xsl:attribute name="alt">Call us</xsl:attribute>
                </xsl:element>
              </a>
            </div>
          </xsl:when>
          <xsl:when test="CallToAction='online'">
            <div>
              <a href="#">
                <xsl:element name="img">
                  <xsl:attribute name="src">click_to_call.png</xsl:attribute>
                  <xsl:attribute name="alt">Call us</xsl:attribute>
                </xsl:element>
              </a>
            </div>
          </xsl:when>
        </xsl:choose>
      </td>
    </tr>
  </xsl:template>
  <xsl:template name="county_map">
    <xsl:param name="cid"/>
    <xsl:choose>
      <xsl:when test="$cid='A'">
        <xsl:value-of select="$sf_county_a"/>
      </xsl:when>
      <xsl:when test="$cid='B'">
        <xsl:value-of select="$sf_county_b"/>
      </xsl:when>
      <xsl:when test="$cid='C'">
        <xsl:value-of select="$sf_county_c"/>
      </xsl:when>
      <xsl:when test="$cid='D'">
        <xsl:value-of select="$sf_county_d"/>
      </xsl:when>
      <xsl:when test="$cid='E'">
        <xsl:value-of select="$sf_county_e"/>
      </xsl:when>
      <xsl:when test="$cid='F'">
        <xsl:value-of select="$sf_county_f"/>
      </xsl:when>
      <xsl:when test="$cid='G'">
        <xsl:value-of select="$sf_county_g"/>
      </xsl:when>
      <xsl:when test="$cid='H'">
        <xsl:value-of select="$sf_county_h"/>
      </xsl:when>
      <xsl:when test="$cid='I'">
        <xsl:value-of select="$sf_county_i"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$sf_county_default"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Open in new window

0
 

Author Comment

by:al4ddin
ID: 35070973
What I need is to display ten records, then insert a row with some default text, display the next ten records and insert the row again and so on...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 35071430
you could pass a parameter here

                                <xsl:for-each select="$records">
                                    <!-- Sort by price in descending/asceding-->
                                    <xsl:sort data-type="{$data-type}" order="{$sort_order}" select="*[name(.)=$sort]"/>
                                    <!-- <xsl:sort order="{$sort_order}" select="*[name(.)=$sort]"/> -->
                                    <xsl:call-template name="record">
                                        <xsl:with-param name="extra-row">
                                            <xsl:choose>
                                                <xsl:when test="position() mod 10 = 0"><xsl:value-of select="true()"/></xsl:when>
                                                <xsl:otherwise><xsl:value-of select="false()"/></xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:with-param>
                                    </xsl:call-template>
                                </xsl:for-each>

and
add the parameter here
    <xsl:template name="record">
      <xsl:param name="extra-row"/>

now you can test for this parameter being "true" and if it does put the extra row
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35071436
all of this is untested, since you gave me no XML to test and only a small portion of the XSLT
0
 

Author Comment

by:al4ddin
ID: 35071658
hmmm, doesn't seem to work!?

How/where would I add the extra row html?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35072148
in the named template for record

if it does not happen there, it might be that you ar enot getting them there in portions of ten,
if that is not the case, it will be difficult to get done
0
 

Author Comment

by:al4ddin
ID: 35081349
Hi Gertone,

Do you have an email address I can email you my full XSLT and XML?

Or does it have to be on here?

Thanks
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35082087
my email address is in my profile (be it somewhat hidden), you can send it there
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

775 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question