473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Define a variable with variables

Is there a way to define a variable by resolving other variables?

I'm trying to build an "uber-variable" from user-selected components. I
have control over the XML and can change it as needed.

The user is allowed to specify one to three data fields from a list and
up to three text fields to use as the pattern for creating chapter
names:

<ChapterNameDefaults>
<Data>PartCode</Data>
<Text> </Text>
<Data>SectionNumber</Data>
<Text>.</Text>
<Data>ChapterNumber</Data>
</ChapterNameDefaults>

I need to create a "dynamically concatenated variable" that would
result if something like this was possible:

<xsl:variable name="ChapterName" select="{$PartCode}{
}{$SectionNumber}{.}{$ChapterNumber}"/>

or

<xsl:variable name="ChapterName" >
<xsl:value-of select="$PartCode"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$SectionNumber"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="$ChapterNumber"/>
</xsl:variable>

which would be dynamically resolved to something like "ADR 0.1" or
"Billing 24-4" (in this example) depending on the user's selection of
variables, their resolved values, and Text.

Of course I could output a resolved ChapterName in the XML to start
with, rather than at the XSL stage, but I'd rather do it in the XSL if
possible.

Suggestions appreciated.
Thx

Jul 20 '05 #1
3 1780
ax***@axialinfo.com writes:
Is there a way to define a variable by resolving other variables?
yes (I think, it depends what you mean)

I'm trying to build an "uber-variable" from user-selected components. I
have control over the XML and can change it as needed.

The user is allowed to specify one to three data fields from a list and
up to three text fields to use as the pattern for creating chapter
names:

<ChapterNameDefaults>
<Data>PartCode</Data>
<Text> </Text>
<Data>SectionNumber</Data>
<Text>.</Text>
<Data>ChapterNumber</Data>
</ChapterNameDefaults>

I need to create a "dynamically concatenated variable" that would
result if something like this was possible:

<xsl:variable name="ChapterName" select="{$PartCode}{
}{$SectionNumber}{.}{$ChapterNumber}"/>
select takes an XPath expression and Xpath expressions never use {}
which are not special characters to Xpath, they may only appear in
strings. (XSLT uses them in attribute value templates to surround an
Xpath, but that's a different context)
You could use

select="concat($PartCode, ' ',$SectionNumber,'.',$ChapterNumber)"

or

<xsl:variable name="ChapterName" >
<xsl:value-of select="$PartCode"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$SectionNumber"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="$ChapterNumber"/>
</xsl:variable>

The above is perfectly legal. Perhaps your question isn't really about
the concatenation but on how to define $PartCode and friends?
which would be dynamically resolved to something like "ADR 0.1" or
"Billing 24-4" (in this example) depending on the user's selection of
variables, their resolved values, and Text.

Of course I could output a resolved ChapterName in the XML to start
with, rather than at the XSL stage, but I'd rather do it in the XSL if
possible.

Suggestions appreciated.
Thx


David
Jul 20 '05 #2
>> The above is perfectly legal. Perhaps your question isn't really
about
the concatenation but on how to define $PartCode and friends?

Yes, you're right, that's where I can't quite make the leap, how to
get from

<Data>PartCode</Data>

to specifying it as a variable name and then resolving it.

=====
<a carlisle across the pond ;-) >

Jul 20 '05 #3
that's where I can't quite make the leap, how to
get from

<Data>PartCode</Data>

to specifying it as a variable name and then resolving it.

You wouldn't do that, variable refernces are compile time constructs
(just as they are in other languages such as C for example) so they
never depend on any run time information.

Your original post wasn't very clear what the input looked like.

You posted this:
<ChapterNameDefaults>
<Data>PartCode</Data>
<Text> </Text>
<Data>SectionNumber</Data>
<Text>.</Text>
<Data>ChapterNumber</Data>
</ChapterNameDefaults>

which I take it you want to be a template for the output but what is the
actual data like? I'll make a guess:

<Chapter>
<ChapterNumber>2</ChapterNumber>
<SectionNumber>3</SectionNumber>
<PartCode>1</PartCode>
<stuff>...</stuff>
</Chapter>
in which case

<xsl:template match="Chapter">
<xsl:variable name="ChapterName" >
<xsl:apply-templates select="/path/to/ChapterNameDefaults/*">
<xsl:with-param name="thischap" select"."/>
</xsl:apply-templates>
</xsl:variable>

..... <xsl:value-of select="$ChapterName"/>
</xsl:template>

<xsl:template match="ChapterNameDefaults/Data">
<xsl:param name="thischap"/>
<xsl:value-of select="$thischap/*[name()=current()]"/>
</xsl:template>
David
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: srinivas reddy | last post by:
I have defined some variables using #define preprocessor instruction. And then later I checked whether I had defined a variable. Sometimes even though a variable have been defined, #if...
12
by: David WOO | last post by:
Hi, I am a newbie on C++, I need to define some global variables which should be accessible to most classes. In the mean time, I don't won't the global variables be modified freely at most of...
6
by: David T. Ashley | last post by:
Hi, In my project, I typically declare and define variables in the .H file, i.e. DECMOD_MAIN UINT8 can_message_201_status_global #ifdef MODULE_MAIN = HAS_NEVER_BEEN_RECEIVED #endif ;
21
by: Angel Lopez | last post by:
Sorry if I am too naive, but this is my first post... I have a binary variable (it can contain either a 0 or a 1). Is there any way I can define a data type that uses only 1 bit. So far I have...
11
by: Jürgen Hochwald | last post by:
Hi Maybe this is a simple question, but I don't know how to solve. Background: A weather station connected to the serial port sends data packets. This data packets are containing variables fom...
6
by: msigwald | last post by:
The following line of code works, however, since my professor is a real purist of c, I would like to know if this code is valid (is it good code or a piece of crap?): #define DMP_FILE argv ...
5
by: MoslyChang | last post by:
Hi, All When I look at effective c++,item2 and item3. I have some basic questions , Does anyone be familar with this topic? it suggests const is perfer to #define, then I think how to replace...
1
by: Bryan Parkoff | last post by:
An object can be defined using a class. The class contains variables and functions. It has a pointer to bind variables and functions. If I want to create more than one object. The class can...
3
by: Immortal Nephi | last post by:
The rule of inheritance states that you define from top to bottom. Sometimes, you want to define base class and set reference from dervied class to base class, but you violate the rule. Here is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.