This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Retriving next 10 elements?


Vetrievel,

Probably your message didn't get through to the list, which refuses
attachments - you should include your files within the messages in order to
send them.

>  Thank you for  your suggestions.We tried with your way.Still it is not
>working.For your reference we have attached those xml&xsl files.We can't
>understand where we are going wrong.If you give your suggestions,it will
>help us  a lot.

OK, you've obviously taken a stylesheet that used the simplified syntax,
just consisting of a literal result element, and then added an xsl:template
into the middle of it.  You can't have a template in the middle of a
simplified stylesheet - you have to convert it to a proper stylesheet to
add the template.

To convert your simplified stylesheet into a proper stylesheet, wrap what
you have within an xsl:template that matches on the root node:

<xsl:template match="/">
  <!-- content of the simplified stylesheet -->
</xsl:template>

And then wrap that template (and any other instructions you want) within an
xsl:stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:template match="/">
  <!-- content of the simplified stylesheet -->
</xsl:template>

<!-- other templates -->

</xsl:stylesheet>

In your example, you don't have to go through this because you can just use
xsl:for-each rather than applying templates to achieve the effect you want
to achieve.  The stylesheet can thus be:

---- employeeSS.xsl ----
<?xml version="1.0"?>
<div xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">
  <table border="5">
    <thead>
      <th>Name</th>
      <th>slno</th>
      <th>DOB</th>
      <th>DOJ</th>
      <th>Designation</th>
      <th>Salary</th>
      <th>Emp_id</th>
    </thead>
    <xsl:for-each select="employees/employee[position() mod 5 = 1]">
      <tr><th colspan="7">Set <xsl:value-of select="position()" /></th></tr>
      <xsl:for-each
          select=". | following-sibling::employee[position() &lt; 5]">
        <tr>
          <td style="padding-left:1em">
            <span><xsl:value-of select="Name"/></span>
          </td>
          <td style="padding-left:1em">
            <span><xsl:value-of select="slno"/></span>
          </td>
          <td style="padding-left:1em">
            <span><xsl:value-of select="DOB"/></span>
          </td>
          <td style="padding-left:1em">
            <span><xsl:value-of select="DOJ"/></span>
          </td>
          <td style="padding-left:1em">
            <span><xsl:value-of select="Designation"/></span>
          </td>
          <td style="padding-left:1em">
            <span><xsl:value-of select="Salary"/></span>
          </td>
          <td style="padding-left:1em">
            <span><xsl:value-of select="Emp_id"/></span>
          </td>   
        </tr>
      </xsl:for-each>
    </xsl:for-each>
  </table>
</div>
----

A few words about the changes I've made.

You needed to put the 'version' attribute on the 'div' element be within
the xsl namespace - xsl:version rather than just 'version'.

It wasn't clear from your stylesheet how you wanted to divide up the groups
of five: the stylesheet can process them in groups of five, but presumably
you want them to appear in those groups, so I've added a header at the top
of each group to show them, and labelled them Set 1, Set 2 and so on.

The XPaths that you use in a simplified stylesheet have the current node
being the root node (/), which means that you have to remember to include
the document element in them.

Finally, I've put all your HTML elements in lowercase so that they are
XHTML-compatible.  There's no harm in doing that, so you may as well.

I've tested this stylesheet with Xalan, SAXON and MSXML (July) and it works
in all three.

I hope that helps,

Jeni

Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]