Pangram verdict · v3.3
We believe that this document is fully human-written
AI likelihood · overall
HumanArticle text · 1,627 words · 8 segments analyzed
The SLAX Scripting Language: An Alternate Syntax for XSLTslax-manual Abstract SLAX is an alternate syntax for XSLT, the W3C standard XML-to-XML transformation. XSLT is a powerful language, but uses an XML-based syntax that is painful to read and write. SLAX uses a syntax modeled after PERL and C which promotes the basic concepts of XSLT into first class language constructs. The result is scripts that are easier to develop and maintain. This documentation covers the SLAX language, beginning with an overview and a reference section listing all SLAX statements. SLAX has a number of built-in functions which are also covered. An implementation of the SLAX is available in an open source project called libslax. Built on top of libxslt and libxml2, libslax parses SLAX files and executes them, and can convert between SLAX and XSLT. A debugger and profiler are included. libslax was originally developed as part of the JUNOS Operating System by Juniper Networks and is released under a BSD license. See the "Copyright" file for details. Table of Contents 1 SLAX (Overview) 1.1 Peeking under the hood 1.2 Composite Technologies 1.2.1 XML Concepts 1.2.2 XPath Concepts 1.2.3 XSLT Concepts 1.2.3.1 Templates 1.2.3.2 Unnamed Templates 1.2.3.3 Parameters 1.2.3.4 Variables 1.2.3.5 Mutable Variables 1.2.3.6 Character Encoding 1.2.3.7 Programming Constructs 1.2.3.8 Recursion 1.2.3.9 Context (Dot) 1.2.4 Additional Resources 2 Building Content with SLAX 2.1 Expressions 2.1.1 Using Elements as Function Arguments 2.1.2 expr 2.1.3 uexpr 2.2 Elements 2.2.1 XML Elements
2.2.2 The "element" Statement 2.2.3 JSON Elements 2.2.3.1 Attributes for JSON Elements 2.2.3.2 Encoding JSON Arrays in XML 2.2.3.3 Encoding Invalid JSON Names 2.3 Attributes 2.3.1 XML Attributes 2.3.2 The "attribute" Statement 2.4 Attribute Sets 2.4.1 The "attribute‑set" Statement 2.4.2 The "use‑attribute‑sets" Statement 2.5 Namespaces 2.5.1 The "ns" Statement 2.5.2 The "extension" Statement 2.5.3 The "exclude" Statement 2.5.4 Reserved Prefixes 2.5.5 Default Namespaces for Prefixes 2.6 Processing Instructions 2.6.1 The "processing‑instruction" Statement 2.7 Comments 2.7.1 The "comment" Statement 2.8 Copying Content 2.8.1 The "copy‑of" Statement 2.8.2 The "copy‑node" Statement 2.9 Formatting 2.9.1 The "number" Statement 3 Templates 3.1 Named Templates 3.1.1 The "template" Statement 3.1.2 The "call" Statement 3.1.2.1 Using the "with" Statement with "call" 3.1.2.2 Using Elements As Argument Values 3.1.2.3 The "match" Statement 3.1.3 Example with XSLT Translation 3.2 Match Templates 3.2.1 The "match" Statement 3.2.2 The "apply‑templates" Statement 3.2.3 The "apply‑imports" Statement 3.2.4 The "mode" Statement 3.2.5 The "priority" Statement 3.2.6 The "param" Statement 3.2.7 The "with" Statement 3.3 The "main" Template 4 Programming Constructs 4.1 Variables 4.1.1 The "var" Statement 4.1.2 The "mvar" Statement
4.2 Result Tree Fragments 4.2.1 The ":=" Operator 4.3 Control Statements 4.3.1 The "if" and "else" Statements 4.3.2 The "for‑each" Statement 4.3.3 The "for" Statement 4.3.4 The "while" Statement 4.3.5 The "sort" Statement 4.3.6 The "..." Operator 4.3.7 The "?:" Operator 4.4 Functions 4.4.1 The "function" Statement 4.4.2 The "result" Statement 5 Additional SLAX Statements 5.1 The "#!" Line 5.2 Combining Scripts ("include" and "import") 5.3 The "key" Statement 5.4 The "decimal‑format" Statement 5.5 Messages 5.5.1 The "message" Statement 5.5.2 The "terminate" Statement 5.5.3 The "trace" Statement 5.6 The "output‑method" Statement 5.7 The "fallback" Statement 5.8 Whitespace Handling 5.8.1 The "strip‑space" Statement 5.8.2 The "preserve‑space" Statement 5.9 The "version" Statement 6 SLAX Functions 6.1 SLAX External Functions 6.1.1 slax:base64-decode 6.1.2 slax:base64-encode 6.1.3 slax:break-lines 6.1.4 slax:dampen 6.1.5 slax:document 6.1.6 slax:evaluate 6.1.7 slax:first-of 6.1.8 slax:get-command 6.1.9 slax:get-input 6.1.10 slax:get-secret 6.1.11 slax:is-empty
6.1.12 slax:printf 6.1.13 slax:regex 6.1.14 slax:sleep 6.1.15 slax:split 6.1.16 slax:sysctl 6.1.17 slax:syslog 7 The libslax Distribution 7.1 The libslax Library 7.2 slaxproc: The SLAX Processor 7.2.1 Argument Handling 7.2.1.1 "#!" Support 7.2.2 Command Line Options 7.2.2.1 Modes Options 7.2.2.2 Behavioral Options 7.3 The SLAX Debugger (sdb) 7.4 The SLAX Profiler 7.5 callflow 8 Extension Libraries in libslax 8.1 The "bit" Extension Library 8.2 The "curl" Extension Library 8.2.1 curl Elements 8.2.1.1 <cc> 8.2.1.2 <connect‑timeout> 8.2.1.3 <contents> 8.2.1.4 <content‑type> 8.2.1.5 <errors> 8.2.1.6 <fail‑on‑error> 8.2.1.7 <format> 8.2.1.8 <from> 8.2.1.9 <header> 8.2.1.10 <insecure> 8.2.1.11 <local> 8.2.1.12 <method> 8.2.1.13 <param> 8.2.1.14 <password> 8.2.1.15 <secure> 8.2.1.16 <server> 8.2.1.17 <subject> 8.2.1.18 <timeout> 8.2.1.19 <to> 8.2.1.20 <upload> 8.2.1.21 <url> 8.2.1.22 <username>
8.2.1.23 <verbose> 8.2.2 curl Extension Functions 8.2.2.1 curl:perform 8.2.2.2 curl:open 8.2.2.3 curl:set 8.2.2.4 curl:single 8.2.2.5 curl:close 8.2.3 Examples 8.2.3.1 Simple GET 8.2.3.2 Google Auth 8.2.3.3 Email 8.3 The "db" Extension Library 8.3.1 db Elements 8.3.1.1 <engine> 8.3.1.2 <database> 8.3.1.3 <collection> 8.3.1.4 <fields> 8.3.1.5 <field> 8.3.1.6 <instance> 8.3.1.7 <instances> 8.3.1.8 <condition> 8.3.1.9 <conditions> 8.3.1.10 <retrieve> 8.3.1.11 <sort> 8.3.1.12 <limit> 8.3.1.13 <skip> 8.3.1.14 <result> 8.3.2 db Extension Functions 8.3.2.1 db:open() 8.3.2.2 db:create() 8.3.2.3 db:insert() 8.3.2.4 db:update() 8.3.2.5 db:delete() 8.3.2.6 db:find()
8.3.2.7 db:fetch() 8.3.2.8 db:find-and-fetch() 8.3.2.9 db:query() 8.3.2.10 db:close() 8.4 The "xutil" Extension Library 8.4.1 "xutil" Extension Functions 8.4.1.1 xutil:max-call-depth() 8.4.1.2 xutil:string-to-xml() 8.4.1.3 xutil:xml-to-string() 8.4.1.4 xutil:json-to-xml() 8.4.1.5 xutil:xml-to-json() 8.5 The "os" Extension Library 8.5.1 "os" Extension Functions 8.5.1.1 Error Nodes 8.5.1.2 os:chmod 8.5.1.3 os:chown 8.5.1.4 os:exit-code 8.5.1.5 os:mkdir 8.5.1.6 os:stat 8.5.1.7 os:user-info Author's Address A Example Stylesheets A.1 general/itemschoose.xsl A.2 REC2/svg.xsl A.3 XSLTMark/metric.xsl B Additional Notes B.1 Language Notes B.1.1 Type Promotion for XPath Expressions B.1.2 The Ternary Conditional Operator B.1.3 Mutable Variables B.2 Historical Notes B.2.1 Why on earth did you make SLAX? B.2.2 Why the name conflict? B.2.2.1 What about the SLAX linux distro? B.3 Developers Notes B.3.1 Dynamic Extension Libraries B.3.2 Default Prefixes for Extension Libraries B.3.3 Example B.4 External Documentation 1_ SLAX (Overview) XSLT is a commonly used transformation language for XML. It is a declarative language that uses XPath expressions to inspect an XML input document and can generate XML output based on that input hierarchy. It's a simple but powerful tool for handling XML, but the syntax is problematic for developers.
XSLT uses an XML-based syntax, and while XML is great for machine-to-machine communication, it is inconvenient for humans to write, especially when writing programs. The occasional benefits of having an XSLT stylesheet be an XML document are outweighed by the readability issues of dealing with the syntax. SLAX has a simple syntax which follows the style of C and Perl. Programming constructs and XPath expressions are moved from XML elements and attributes to first class language constructs. XML angle brackets and quotes is replaced by parentheses and curly braces which are familiar delimiters for programmers. SLAX allows you to: Use if/then/else instead of <xsl:choose> and <xsl:if> elements Put test expressions in parentheses Use "==" to test equality (to avoid building dangerous habits) Use curly braces to show containment instead of closing tags Perform concatenation using the "_" operator (lifted from perl6) Perform simple logic using the "?:" operator Write text strings using simple quotes instead of the <xsl:text> element Simplify invoking named templates with a syntax resembling a function call Simplify defining named template with a syntax resembling a function definition Simplify namespace declarations Reduce the clutter in scripts, allowing the important parts to be more obvious to the reader Write more readable scripts The benefits of SLAX are particularly strong for new developers, since it puts familiar constructs in familiar syntax, allowing them to concentrate in the new topics introduced by XSLT. Section Contents: Section1.1 Section1.2 1.1 Peeking under the hood SLAX is purely syntactic sugar. The underlaying constructs are completely native to XSLT. All SLAX constructs can be represented in XSLT. The SLAX parser parses an input document and builds an XML tree identical to one produced when the XML parser reads an XSLT document. SLAX can be viewed as a pre-processor for XSLT, turning SLAX constructs (like if/then/else) into the equivalent XSLT constructs (like <xsl:choose> and <xsl:if>) before the real XSLT transformation engine gets invoked. The current distribution for libslax is built on libxslt. SLAX uses the xsltSetLoaderFunc() in libxslt to tell libxslt to use a different function when loading script documents.
When xsltParseStylesheetDoc() loads a script, it then calls the SLAX loader code, which reads the script, constructs an XML document (xmlDoc) which mimics the document the normal XML parser would have created for a functionally equivalent script. After this document is returned to the existing libxslt code, normal XSLT processing continues, unaffected by the fact that the script was written in SLAX. The "build‑as‑if" nature of SLAX makes is trivial to write a SLAX-to-XSLT convertor, which reads in SLAX and emits XSLT using the normal libxslt file writing mechanism. In addition, an XSLT-to-SLAX convertor is also available, which emits an XSLT document in SLAX format. These make a great learning aid, as well as allowing conversion of SLAX scripts to XSLT for environments where libxslt is not available. 1.2 Composite Technologies SLAX builds on three existing technologies, XML, XPath, and XSLT. XML is a set of encoding rules that allow simplified parsing of documents, which gives a simple way to represent hierarchical data sets in text. XML parsers can be used to encode any type of content, and their reuse has breed a set of high-quality implementations that can be easily incorporated into any software project. Having a single encoding helps removing parsing errors, increase code reuse, simplify developer interaction, reduce development costs, and reduce errors. XPath is an expression language that allows the specification of sets of nodes within an XML document. The language is simultaneously powerfully expressive in terms of the nodes that can be selected, but also simple and readable. It follows the path of making simple things simple, while making hard things possible. XSLT is a transformation language that turns XML input document into an XML output document. The basic model is that an XSLT engine (or "processor") reads a script (or stylesheet) and an XML document. The XSLT engine uses the instructions in the script to process the XML document by traversing the document's hierarchy. The script indicates what portion of the tree should be traversed, how it should be inspected, and what XML should be generated at each point. We'll examine each of these technologies in more detail in the following sections.