YouTip LogoYouTip

Xsl Client

β€” Learning is not just about technology, but also about dreams! Home HTML JAVASCRIPT CSS VUE REACT PYTHON3 JAVA C C++ C# AI GO SQL LINUX VS CODE BOOTSTRAP GIT Local Bookmarks XSLT Tutorial XSLT Tutorial XSL Language Introduction to XSLT XSLT Browsers XSLT Transformation XSLT XSLT XSLT XSLT XSLT XSLT XSLT Apply XSLT on the Client Side XSLT on the Server Side XSLT Editing XML XML Editors XSLT Summary XSLT Examples XSLT Elements XSLT Functions XSLT Transformation Tools XSLT Element XSLT on the Server Side In-Depth Exploration Web Browsers Programming Web Software Utilities script Scripting Languages Web Design & Development Web Service Development Tools Software XSLT β€” On the Client Side If your browser supports XSLT, it can be used within the browser to transform documents into XHTML. JavaScript Solution In previous chapters, we have shown you how to use XSLT to transform an XML document into XHTML. We accomplished this by adding an XSL stylesheet reference to the XML file and letting the browser perform the transformation. Although this method works well, embedding a stylesheet reference directly in the XML file is not always satisfactory (e.g., this approach fails in browsers that do not support XSLT). A more universal solution is to use JavaScript to perform the transformation. Using JavaScript, we can: Perform browser compatibility testing Use different stylesheets based on the browser type and user requirements This is where XSLT shines! One of XSLT’s design goals is precisely to enable data transformation from one format to another while supporting diverse browser types and varying user needs. Client-side XSLT transformations will certainly become one of the primary tasks performed by future browsers, and we’ll also see growth in specialized browser markets (e.g., Braille browsers, audio browsers, web printers, handheld devices, etc.). XML File and XSL File Consider the following XML document, which was already demonstrated in earlier chapters: Example Empire Burlesque Bob Dylan USA Columbia 10.90 1985 . . View the XML file. And here is its accompanying XSL stylesheet: Example Β 

My CD Collection

Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β 
TitleArtist
View the XSL file. Note that this XML file does not contain any reference to the XSL file. Important Note: This means the XML file can be transformed using multiple different XSL stylesheets. Note: Ensure the XSL file is accessible via a direct link in the browser, as shown below: Otherwise, you may encounter the error: Uncaught TypeError: Failed to execute 'importStylesheet' on 'XSLTProcessor': parameter 1 is not of type 'Node'. Transforming XML to XHTML in the Browser Below is the source code for transforming an XML file into XHTML on the client side: Example function loadXMLDoc(filename) { if (window.ActiveXObject) { xhttp = new ActiveXObject("Msxml2.XMLHTTP"); } else { xhttp = new XMLHttpRequest(); } xhttp.open("GET", filename, false); try { xhttp.responseType = "msxml-document" } catch (err) {} // Helping IE11 xhttp.send(""); return xhttp.responseXML; } function displayResult() { xml = loadXMLDoc("cdcatalog.xml"); xsl = loadXMLDoc("cdcatalog.xsl"); // code for IE if (window.ActiveXObject || xhttp.responseType == "msxml-document") { ex = xml.transformNode(xsl); document.getElementById("example").innerHTML = ex; } // code for Chrome, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { xsltProcessor = new XSLTProcessor(); xsltProcessor.importStylesheet(xsl); resultDocument = xsltProcessor.transformToFragment(xml, document); document.getElementById("example").appendChild(resultDocument); } }
Try it Β» Tip: If you are unfamiliar with writing JavaScript, please study our JavaScript tutorial. Explanation of the Example: loadXMLDoc() Function The loadXMLDoc() function loads XML and XSL files. It checks the browser type used by the user and the file-loading capability. displayResult() Function This function displays the XML file styled according to the definitions in the XSL file. Loads the XML and XSL files Tests the user's browser type If the user’s browser supports ActiveX objects: Applies the XSL stylesheet to the XML document using the transformNode() method Sets the body of the current document (id="example") to contain the styled XML document If the user’s browser does not support ActiveX objects: Creates a new XSLTProcessor object and imports the XSL file Applies the XSL stylesheet to the XML document using the transformToFragment() method Sets the body of the current document (id="example") to contain the styled XML document XSLT Element XSLT on the Server Side Byte Ark Coding Plan Supports mainstream large models including Doubao, GLM, DeepSeek, Kimi, MiniMax, etc.; officially supplied, stable and reliable. Β₯9.9 / month Sign Up Now iFLYTEK Xingchen Coding Plan Includes free model invocation quotas; supports DeepSeek, GLM, Kimi, MiniMax β€” an all-in-one platform for experience and deployment. Β₯3.9 / month Sign Up Now Click to Share Notes Category Navigation Python / Data Science AI / Intelligent Development Frontend Development Backend Development Databases Mobile Development DevOps / Engineering Programming Languages Computer Fundamentals XML / Web Service .NET Website Development Advertisement XSLT Tutorial XSLT Tutorial XSL Language Introduction to XSLT XSLT Browsers XSLT Transformation XSLT Online Examples Β·HTML Examples Β·CSS Examples Β·JavaScript Examples Β·Ajax Examples Β·jQuery Examples Β·XML Examples Β·Java Examples Character Sets & Tools Β· HTML Character Set Configuration Β· HTML ASCII Character Set Β· JS Obfuscation/Encryption Β· PNG/JPEG Image Compression Β· HTML Color Picker Β· JSON Formatter Tool Β· Random Number Generator Latest Updates Β· docker compose ... Β· GraphRAG Beginner Tutorial Β· Dart Enums and Symbols Β· Dart Unit Testing Β· Dart Concurrency and Iso... Β· Dart Stream Β· Dart Asynchronous Programming Site Information Β· Feedback Β· Disclaimer Β· About Us Β· Article Archive Follow on WeChat My Favorites Bookmark Articles Browsing History Clear All No records yet
← Xsl ServerXsl Apple Templates β†’