Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 495
  • Last Modified:

inserting table row every tens rows XSLT

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
al4ddin
Asked:
al4ddin
  • 5
  • 4
1 Solution
 
Geert BormansCommented:
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
 
al4ddinAuthor Commented:

<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
 
al4ddinAuthor Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Geert BormansCommented:
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
 
Geert BormansCommented:
all of this is untested, since you gave me no XML to test and only a small portion of the XSLT
0
 
al4ddinAuthor Commented:
hmmm, doesn't seem to work!?

How/where would I add the extra row html?
0
 
Geert BormansCommented:
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
 
al4ddinAuthor Commented:
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
 
Geert BormansCommented:
my email address is in my profile (be it somewhat hidden), you can send it there
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now