XSLT Transformation Script Outline
Define structure, parameters, and key templates for XSLT 1.0/2.0 stylesheets.
Transformation Metadata
Global Parameters
Template Definitions
No templates defined.
'; return; } templates.forEach(t => { const item = document.createElement('div'); item.className = 'xslt-list-item bg-white'; item.innerHTML = ` ${escapeHtml(t.match)} ${escapeHtml(t.desc)} `; list.appendChild(item); }); } // --- Code Generation --- function xsltGenerateCode() { const version = document.getElementById('xslt-version').value; const outputMethod = document.getElementById('xslt-output-method').value; const encoding = document.getElementById('xslt-encoding').value; const rootName = document.getElementById('xslt-root-name').value || "root"; const date = new Date().toLocaleDateString('en-US'); let code = ` <!-- Generated XSLT StyleSheet Outline --> <!-- Date: ${date} --> <xsl:stylesheet version="${version}" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"${version === '2.0' ? ' xmlns:xs="http://www.w3.org/2001/XMLSchema"' : ''} > `; // Output Declaration code += ` <xsl:output method="${outputMethod}" encoding="${encoding}" /> `; // Global Parameters if (globalParams.length > 0) { code += ` <!-- Global Parameters defined for external injection -->`; globalParams.forEach(p => { code += ` <xsl:param name="${p.name}" select="${p.defaultVal}" />`; }); } // Root Template code += ` <!-- Template 1: Root document entry point --> <xsl:template match="/"> <!-- Start the main output container --> <${outputMethod === 'html' ? 'html' : 'document'}> <xsl:apply-templates select="/${rootName}" /> </${outputMethod === 'html' ? 'html' : 'document'}> </xsl:template> `; // User Defined Templates if (templates.length > 0) { code += ` <!-- User Defined Templates -->`; templates.forEach((t, index) => { code += ` <!-- Template ${index + 2}: ${t.desc} --> <xsl:template match="${t.match}"> <!-- Insert logic here --> <xsl:value-of select="." /> </xsl:template> `; }); } code += ` </xsl:stylesheet> `; document.getElementById('xslt-code-output').innerHTML = code; } // --- PDF Download --- window.xsltDownloadPDF = function() { // Ensure code is generated before downloading xsltGenerateCode(); const element = document.getElementById('xslt-code-output'); document.body.classList.add('xslt-generating-pdf'); const opt = { margin: [0.5, 0.5], filename: `XSLT_StyleSheet_Outline.pdf`, image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true }, jsPDF: { unit: 'in', format: 'letter', orientation: 'landscape' } }; html2pdf().set(opt).from(element).save().then(() => { document.body.classList.remove('xslt-generating-pdf'); }); }; // Utility: HTML Escape function escapeHtml(text) { if (!text) return ''; return text.replace(/[&<>"']/g, function(m) { switch (m) { case '&': return '&'; case '<': return '<'; case '>': return '>'; case '"': return '"'; case "'": return '''; default: return m; } }); }