1. Este site usa cookies. Ao continuar a usar este site está a concordar com o nosso uso de cookies. Saber Mais.

paging xsl xslt

Discussão em 'Web Development' iniciada por alfinete, 11 de Setembro de 2008. (Respostas: 0; Visualizações: 1175)

  1. alfinete

    alfinete Power Member

    teste .html
    ________________________________________________
    Código:
    
    <html>
    
    <head>
    <link rel="stylesheet" type="text/css" href="noticias.css">
    <script type="text/javascript">
    function loadXMLDoc(fname)
    {
    var xmlDoc;
    // code for IE
    if (window.ActiveXObject)
      {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation 
    && document.implementation.createDocument)
      {
      xmlDoc=document.implementation.createDocument("","",null);
      }
    else
      {
      alert('Your browser cannot handle this script');
      }
    xmlDoc.async=false;
    xmlDoc.load(fname);
    return(xmlDoc);
    }
    
    function displayResult()
    {
    xml=loadXMLDoc("teste3.xml");
    
    xsl=loadXMLDoc("teste3.xslt");
    // code for IE
    if (window.ActiveXObject)
      {
      ex=xml.transformNode(xsl);
      document.getElementById("teste").innerHTML=ex;
      }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation 
    && document.implementation.createDocument)
      {
      xsltProcessor=new XSLTProcessor();
      xsltProcessor.importStylesheet(xsl);
      resultDocument = xsltProcessor.transformToFragment(xml,document);
      document.getElementById("teste").appendChild(resultDocument);
      }
    }
    </script>
    </head>
    <body id="teste" onLoad="displayResult()">
    </body>
    </html>
    
    
    teste .xslt
    ____________________________

    Código:
    
    <?xml version="1.0" encoding="utf-8"?>
    <!--
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                                  xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
                                  xmlns:vt="http://www.viatecla.pt/" >-->
                                  
    <xsl:stylesheet version="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" 
                                  xmlns:HTML ="http://www.w3.org/Profiles/XHTML-transitional">
        <xsl:template match="/">
          <xsl:variable name="maxItemsPage" select="2"/>
    
          <HTML>
              <HEAD>
                <SCRIPT language="JavaScript">
                   <xsl:comment>
                    <![CDATA[
    
                      function displayPage(from, to)
                      {
                        //Need to set the params to $to and $from 
                        source = new ActiveXObject("MSXM3.FreeThreaderDOMDocument");
                        var s = document.XSLDocument.selectSingleNode("*/xsl:template[@match='Data']//xsl:apply-templates");
                        var d = document.XMLDocument.selectSingleNode("Status/Data");
                        Table.innerHTML = d.transformNode(document.XSLDocument);
                      }
    
                      function sort(key)
                      {
                        var s = document.XSLDocument.selectNodes("*/xsl:template[@match ='Data']//xsl:[email protected]");
                        for (var i = s.nextNode(); i != null; i = s.nextNode())
                        {
                            i.value = key;
                        }
                        var d = document.XMLDocument.selectSingleNode("Status/Data");
                        Table.innerHTML = d.transformNode(document.XSLDocument);
                      }
                     ]]>
                  </xsl:comment></SCRIPT>
              </HEAD>
    
              <BODY>
                <TABLE WIDTH="100%" BORDER="1" CELLSPACING="1">
                    <TR>
                         <TD colspan="3"><DIV id="Table">
                               <xsl:apply-templates select="Status/Data"/>
                         </DIV>
                         </TD>
                    </TR>
                </TABLE>
                <P/>
              </BODY>
            </HTML>
        </xsl:template>
    
        <xsl:template match="Data">
          <xsl:variable name="from" select="1"/>
          <xsl:variable name="to" select="2"/>
          <xsl:call-template name="tableheader"/>
          <xsl:apply-templates select="//Uow[position() &gt;= $from and position() &lt;= $to]"/>
          <xsl:call-template name="pagefooter"/>
        </xsl:template>
    
        <xsl:template name="tableheader">
        
              <TR>
                <th><A href="javascript:sort('senderId')">Sender ID</A></th>
                <th><A href="javascript:sort('docId')">Document Id</A></th>
              </TR>
              
        </xsl:template>
    
        <xsl:template name="pagefooter">
        
          <xsl:variable name="from" select="1"/>
          <xsl:variable name="to" select="2"/>
              <TR>
                  <th><a href="javascript:displayPage({$from - 2}, {$from - 1})">Back</a></th>
                  <th><a href="javascript:displayPage({$to + 1}, {$to + 2})">Next</a></th>
              </TR>
        
        </xsl:template>
    
        <xsl:template match="Uow">
           <tr>
                <td>
                   <xsl:value-of select="senderId"/>
                </td>
                <td>
                   <xsl:value-of select="docId"/>
                </td>
           </tr>
        </xsl:template>
    
    </xsl:stylesheet>
    
    
    

    teste .xsl
    ____________________________


    Código:
    
    
    <?xml version="1.0" encoding="UTF-8" ?>
    
    <?xml-stylesheet type="text/xsl" href="teste3.xslt"?>
    
    
    
    <Status xmlns:HTML="http://www.w3.org/Profiles/XHTML-transitional">
         <Data>
             <Uow uuid="300">
                 <senderId>BNBNT-1</senderId>
                 <docId>1</docId>
             </Uow>
             <Uow uuid="345">
                 <senderId>BNBN</senderId>
                 <docId>2</docId>
             </Uow>
             <Uow uuid="678">
                 <senderId>AMZN</senderId>
                 <docId>3</docId>
             </Uow>
             <Uow uuid="910">
                <senderId>EBAY</senderId>
                <docId>4</docId>
             </Uow>
             <Uow uuid="999">
                <senderId>INDUS</senderId>
                <docId>5</docId>
             </Uow>
         </Data>
    </Status>
    
    
    pus aqui tdos os ficheiros

    o que corre tudo é o teste.html

    o que eu gstava de fazer e esta a dar um erro, é fazer um paging(paginação) em xsl resultante de dados xml

    gostava de um help para o problema

    obrigada
     

Partilhar esta Página