Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

inserting table row every tens rows XSLT

Posted on 2011-03-08
9
Medium Priority
?
493 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

688 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