EXEMPLO:
Temos a webpart customizada, com aquele código XSL gigantesco nativo. Nós deletaremos a tag "<xsl:stylesheet>" inteira, substituindo-a pelo código abaixo:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ddwrt2="urn:frontpage:internal"> <xsl:import href="/Style Library/XSL Style Sheets/NomeDoArquivo.xsl"/> <xsl:template match="/"> <xsl:apply-imports/> </xsl:template> </xsl:stylesheet>
Basicamente estamos dizendo que, ao carregar a webpart ele irá trazer informações deste arquivo externo que está no xsl:import. Estes arquivos .xsl ficam dentro da Style Library > XSL Style Sheets.
UPDATE DO ROLÊ!
Outra dica importante que descobrimos:
Dentro deste arquivo .xsl existe um código padrão a ser adicionado, abaixo segue um modelo a ser utilizado:
<xsl:stylesheet version="1.0" exclude-result-prefixes="x d xsl msxsl cmswrt ddwrt" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"> <xsl:include href="/_layouts/15/xsl/main.xsl"/> <xsl:include href="/_layouts/15/xsl/internal.xsl"/> <xsl:include href="/Style Library/XSL Style Sheets/Utils.xsl"/> <xsl:param name="AllRows" select="/dsQueryResponse/Rows/Row[$EntityName = '' or (position() >= $FirstRow and position() <= $LastRow)]"/> <xsl:param name="dvt_apos">'</xsl:param> <xsl:template match="/"> </xsl:template> </xsl:stylesheet>
Neste modelo acima, estamos usando uma tag diferente na primeira linha. esta tag stylesheet não insere atributos do SharePoint em seu html, deixando ele muito mais "clean" e facil de ler. Também deixei uma tag chamada <xsl:include que serve para fazer chamada de outro XSL dentro deste, ou seja, usamos para chamar um utils.xsl onde colocamos vários templates de XSL customizados.
E é isso, muito útil e facil de trabalhar, afnal, gostamos de códigos html mais limpos, correto? :D
Abraços!
0 comentários:
Postar um comentário