Subject: Re: [xsl] Indirect referencing in XSLT/XPath? From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 5 Apr 2025 19:22:43 -0000 |
> Is there any way to do indirect referencing in XSLT/XPath? Yes, but not assignments, as in XPath any created variable is immutable. For your particular example: let $aircraft := {"altitude": {"units" : "Flight_Level"} } return $aircraft?altitude?units produces: Flight_Level And this can be executed in a suitable XPath processor, such as BaseX or Oxygen: Thanks, Dimitre. On Sat, Apr 5, 2025 at 7:35b/AM Roger L Costello costello@xxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hi Folks, > > The SNOBOL language has a wicked cool indirect referencing capability. Is > there an indirect referencing capability in XSLT/XPath? > > Here is a brief description of SNOBOL's indirect referencing capability: > > First, let's assign UNITS the string METERS > > UNITS = "METERS" > > In that statement UNITS is a name, and METERS is a data string. > > In this statement UNITS is a data string: > > ALTITUDE = "UNITS" > > Let's output the value of ALTITUDE: > > OUTPUT = ALTITUDE > prints UNITS. > > [In SNOBOL, the word OUTPUT is a keyword; when it is assigned a value, > that value is output. I think that is pure genius.] > > The value of UNITS hasn't changed, as we can see with this output: > > OUTPUT = UNITS > prints METERS. > > SNOBOL has an indirect referencing operation to reference the value of a > value. ["reference the value of a value" Let that sink into your brain; it > is so cool.] The indirect referencing operation is indicated by the unary > operator $ written in front of a name: > > OUTPUT = $ALTITUDE > prints METERS. > > Let's change the value of UNITS: > > UNITS = "FEET" > > Now do an indirect reference: > > OUTPUT = $ALTITUDE > prints FEET. > > Values may be assigned using indirect referencing: > > $ALTITUDE = "FLIGHT_LEVEL" > > We can see that the value of UNITS has changed: > > OUTPUT = UNITS > prints FLIGHT_LEVEL. > > More than one level of indirect referencing is allowed, using $$, $$$, > $$$$, etc. > > We've been using ALTITUDE as a name; now let's use it as a data string: > > AIRCRAFT = "ALTITUDE" > > Here's the reference chain that we've created: AIRCRAFT references > ALTITUDE which references UNITS which references FLIGHT_LEVEL. Stated > another way, AIRCRAFT has a property, ALTITUDE, and ALTITUDE has a > property, UNITS, and UNITS has a value, FLIGHT_LEVEL. > > Let's do some indirect referencing to show the reference chain: > > OUTPUT = AIRCRAFT > prints ALTITUDE > > OUTPUT = $AIRCRAFT > prints UNITS. > > OUTPUT = $$AIRCRAFT > prints FLIGHT_LEVEL. > ---------------------------------------------------- > Okay, that is a quick introduction to SNOBOL's indirect referencing > capability. I think it's wonderful. I can see the utility of changing an > item that is way down the reference chain--e.g., change the value of > UNITS--without impacting items that are way up the reference chain--e.g., > no impact to ALTITUDE or AIRCRAFT. > > XML entities resemble indirect referencing: > > <!DOCTYPE Document [ > <!ENTITY UNITS "FLIGHT_LEVEL"> > <!ENTITY ALTITUDE "&UNITS;"> > <!ENTITY AIRCRAFT "&ALTITUDE;"> > ]> > <Document> > &AIRCRAFT; > </Document> > > I was delighted to see that SNOBOL uses the $ symbol. XSLT/XPath uses the > $ symbol to identify a variable, e.g., $foo. In SNOBOL, the $ symbol is a > unary operator. Does XSLT/XPath consider the $ symbol to be a unary > operator? I don't think that XSLT/XPath permits two consecutive $ symbols, > e.g., $$foo is illegal and $($foo) is illegal, right? > > Is there any way to do indirect referencing in XSLT/XPath? > > /Roger
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Indirect referencing in X, Roger L Costello cos | Thread | Re: [xsl] Indirect referencing in X, Roger L Costello cos |
Re: [xsl] Indirect referencing in X, Peter Flynn peter@xx | Date | Re: [xsl] Indirect referencing in X, Roger L Costello cos |
Month |