4 ms·
Totally agree, XSLT is a great instrument and it can/should be used in a browser too, see http://www.yegor256.com/2014/06/25/xml-and-xslt-in-browser.html http:/
by yegor256a 12y ago
Totally agree, XSLT is a great instrument and it can/should be used in a browser too, see http://www.yegor256.com/2014/06/25/xml-and-xslt-in-browser.html http://www.yegor256.com/2014/06/25/xml-and-xslt-in-browser.h...
- thangalin 12y agoThe following 45 lines of XSL code transforms a simple XML document into XHTML DIV tags that mirror the input structure: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="no" method="html" doctype-system="about:legacy-compat" encoding="utf-8"/> <!-- Action parser that responds to HTTP requests. --> <xsl:param name="action" select="'do.dhtml'"/> <xsl:template match="/"> <html> <head> <meta charset='utf-8'/> <title>Title</title> <link rel='stylesheet' type='text/css' href='css/common.css'/> </head> <body> <xsl:apply-templates/> <script type='text/javascript' src='js/common.js'></script> </body> </html> </xsl:template> <!-- Make the document complete with div elements and classes. --> <xsl:template match="*"> <div class="{local-name()}"><xsl:apply-templates select="node()|@*"/></div> </xsl:template> <!-- The 'id' attribute indicates a link. --> <xsl:template match="*[@id]"> <div class="{local-name()}"><a href="{$action}?action={local-name()}&id={@id}"><xsl:apply-templates select="node()|*"/></a></div> </xsl:template> <!-- Retain the attributes (except if named "class"). --> <xsl:template match="@*"> <xsl:if test="name() != 'class'"><xsl:copy-of select="."/></xsl:if> </xsl:template> </xsl:stylesheet> CSS is then used to customize the presentation layer. For example, all the pages in the following website (click only "Next" and Safari is broken) are completely client-side XSLT, but use an XML document as a starting point: http://djarvis.bitbucket.org/xml/ http://djarvis.bitbucket.org/xml/ The pie chart on the following page was also generated using client-side XSLT: http://djarvis.bitbucket.org/xml/resources.xml http://djarvis.bitbucket.org/xml/resources.xml The only "trick" that was required was to load CSS (and some JavaScript) based on the current filename in the URL: http://djarvis.bitbucket.org/xml/js/common.js http://djarvis.bitbucket.org/xml/js/common.js Most people write one XSLT page per web page to transform, but by using structured DIVs with classes that correspond to the XML element names, only one general-purpose XSL page is required. This demonstrates the separation of content (XML) from presentation (XHTML/CSS).
- julie1 12y agoGive me an input, the expected output, and I will show you I can do a more readable shorter and easier version of the transofrmation with jquery. The XSLT is so unreadable it requires comments. I did once a less than 2k library in js that loaded the TTML markup in an hidden div and would show it on an HTML 5 video player with extra formatting. Why would someone need XSLT in 2014? It was a failure in 2000.