lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, 15 Jun 2010 10:06:39 +0300, David Manura <dm.lua@math2.org> wrote:

True, but try adding conditionals, loops, and local variables in the
middle of that, like XSLT:

  <table><xsl:variable name="x" select=" 'test' " /><tr>
   <xsl:for-each select="1 to 3">
   <xsl:variable name="index" select="."/>
    <td><xsl:value-of select="$index"/><xsl:value-of select="$x"/></td>
   </xsl:for-each>
  </tr></table>

which in a Lisp-like / AST form is

  (table (let x 'test') (tr (fornum i 1 3 (td i x))))

Sure, you can rewrite the analogous form in Lua:

  table { let {'x', 'test'}, tr { fornum { 'i', 1, 3, { td { var 'i',
var 'x' } }} }}

That would be more like:

table { xsl.variable { name="x", select=" 'test' ", tr {
 xsl.for_each { select="1 to 3",
 xsl.variable { name="index", select="." },
  td { xsl.value_of { select="$index" }, xsl.value_of { select="$x" } }
 }
} }

The original XSLT _at syntactic level_ does not have any
conditionals, loops or local variables. It's an XML document.
What I wanted to say in my previous post is that such XML model of
nodes with ordered subnodes that can have duplicates, and
unordered attributes that cannot have duplicates translates
directly into Lua table constructors, and can make use of
environment overrides.