Menu

#16 Program Enhancement Request: Dynamic Variable Naming

open
nobody
5
2015-01-17
2006-05-10
Anonymous
No
   The Saxon implementation of a V1.0 XSLT

processor is forward-thinking in the area of variable
definition and assignment. These Saxon-specific
enhancements can be further extended to allow for
Dynamic Variable Naming. In short, this Program
Enhancement Request defines a syntax by which run-time
variable values can be used to set and retrieve
application data.

   In some applications, there is a need to

construct a variable name by combining a constant,
literal string with a run-time, variable string. An
example of this is as follows:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <br="">xmlns:saxon="http://saxon.sf.net/" saxon:trace="yes" xmlns:date="http://exslt.org/dates-and-times"
xmlns:func="http://exslt.org/functions"
xmlns:css="http://www.customizedsoftwaresolutions.com" extension-element-prefixes="saxon date func css">
<xsl:output method="text" indent="yes"/>
<xsl:variable name="A4.fl" saxon:assignable="yes"/>
<xsl:variable name="TEMP0000" saxon:assignable="yes"/>
<xsl:variable name="TEMP0001" saxon:assignable="yes"/>
. . .
<saxon:assign name="TEMP0000" select="concat ($t,'.fl')"/>
. . .

   At this point, there is a need to set and get

values based on the contents of the variable $TEMP0000.
Three differing syntaxes are proposed:

   Option I: Set

<saxon:assign name="saxon:evaluate ('$p1',$TEMP0000)" select="$TEMP0001"/>
Option I: Get
<xsl:value-of select="saxon:evaluate ('$p1',$TEMP0000)"/><xsl:text>

   Option II: Set

<saxon:assign name="$TEMP0000" select="$TEMP0001"/>
Option II: Get
<xsl:value-of select="$$TEMP0000"/>

   Option III: Set (no intermediate $TEMP0000)

<saxon:assign name="saxon:evaluate(concat ('$p1','.fl'),$t)" select="some_value"/>
Option III: Get (no intermediate $TEMP0000)
<xsl:value-of select="evaluate(concat ('$p1','.fl'),$t)"/>

   Any one of these proposed syntaxes provides

access to the variables values based on the contents
of a refering variable.
Note that these requirements are based in
desired functionality, and not the ease of
implementation of a given solution.(Further note that
these requirements are based on XSLT 1.0. This, or
similar, function may already be defined in XSLT 2.0.)

Comments: customizedsoftwaresolutions@juno.com

Discussion

  • Michael Kay

    Michael Kay - 2006-05-10

    Logged In: YES
    user_id=251681

    Sorry, but this is completely off the wall. Saxon is moving
    more-and-more to looking like a compiler rather than an
    interpreter. The way to achieve your requirement is to
    create a single variable whose value is an XML tree, in
    which the element names can be chosen dynamically.

    saxon:assign is a legacy feature: please don't use it. It
    might disappear one day.

    Michael Kay

     
  • Nobody/Anonymous

    Logged In: NO

    How can I create an XML tree in one portion of a stylesheet
    for reference in another portion of the same stylesheet?
    This would provide the function I am looking for.

    My experience is with XSLT 1.0, and single file output
    (STDOUT). Does XSLT 2.0 provide facilities for multiple
    output XML files from a single stylesheet?

    If neither of these is possible, I am prepared to do
    multiple passes through the XSLT processor to accomplish my
    goal.

    Comments: customizedsoftwaresolutions@juno.com

     
  • Michael Kay

    Michael Kay - 2006-05-11

    Logged In: YES
    user_id=251681

    You create a temporary tree like this:

    <xsl:variable name="xxx">
    <element foo="bar">
    <xsl:thingummy select="cheese"/>
    </element>
    </xsl:variable>

    and you can then pass it around via parameters in the same
    way as any other variable.

    There's an infuriating restriction in 1.0 that you can't
    then examine the tree with path expressions, but every known
    processor (except Mozilla's) has an xx:node-set() extension
    to get around that restriction (and it's gone in 2.0).

     

Log in to post a comment.