473,322 Members | 1,911 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,322 software developers and data experts.

xml conditional if statement

3
Hello everyone,

I have a question about if statements with xml. I need to ensure certain fields have a particular value, if this is true I want to display a large amount of text. Let me give an example below:

if fld_Country="Canada"
if fld_City="Toronto"
if fld_Member="1"
display the following text, "blah blah."

if fld_country"USA"
if fld_city="New York"
if fld_member="2"
display the following text, "blah blah."

if fld_country"Canada"
if fld_City="Toronto"
if fld_Member="2"
display the following text, "blah blah."

if fld_country"Canada"
if fld_City="Ottawa"
display the following text, "blah blah."

end if statements

I am not certain if this is possible to nest so many if statements within a single if statement. Should I use choices? Any advice would be greatly appreicated. Thanks.
Joe.

<code>
<?if@inlines:fld_COUNTRY='Canada'?>?fld_COUNTY_DES CR?><?end if?>
</code>
Nov 11 '08 #1
6 27615
Dormilich
8,658 Expert Mod 8TB
what you want to do seems a bit strange. xml (with some exceptions) is used to store data (statically store, like in a DB).

any condition would need someone/something (that someone is usually called "parser") that actually decides if the condition is fulfilled or not. an xml parser doesn't do that.

in your case I recommend using a script that processes an input giving you the desired xml file.
- xslt (needs xml, returns xml or text)
- any programming language

for the case of xslt your “weapon” of choice is a conditional XPath expression, e.g.
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="element[fld_Country='Canada'][fld_City='Toronto'][fld_Member='1']">
  2. // note that the expression depends on your input xml
  3. <xsl:text>bla bla blubb</xsl:text>
  4. </xsl:template>
in any case I recommend reading a tutorial first, if you're not accustomed to the language you want to use.

XSLT tutorial

if you encounter any problems post back so we can help you getting it right.

regards
Nov 11 '08 #2
jkmyoung
2,057 Expert 2GB
Is the code actually formed like so?
<code>
<?if@inlines:fld_COUNTRY='Canada'?>?fld_COUNTY_DES CR?><?end if?>
</code>

Is the fact that the last query has no Member signficant?

It really depends on how you're going to use your code.
Nov 12 '08 #3
joe2k1
3
Here is a quick follow up.

It would appear I am using XSLT processor.

I need to make certain two conditionals are true for a statement to print.

Unfortunately, I am having one the first statement found to be true and the message is printed!

<?choose:?>
<?when:GENDER='MALE'?>
<?when:AGE='30'?>
Please note that you have been selected to participate in a survery for men who are age 30 this year.
<?end when?>
<?end when?>
<?end choose?>

Here is the error message when I tried to process this syntax


<Line 103, Column 63>: XML-22047: (Error) Invalid instantiation of 'xsl:when' in 'xsl:when' context.


I am unable to determine the exact line but I am 99% certain it relates to the above coding.

Any help or advice would be greatly appreciated!

Thank you.
Feb 6 '09 #4
jkmyoung
2,057 Expert 2GB
You have a nested when. If you want to use a nested when you need to have to have a nested choose with it.
Expand|Select|Wrap|Line Numbers
  1. <choose>
  2.   <when>
  3.       <choose>
  4.           <when>
  5.  
Feb 6 '09 #5
joe2k1
3
I tried the nesting, but unfortunately it didn't work. Here is what I tried below:

<choose>
<when>
<choose>
<when>
if both when conditions are true please show this message.
end when
end choose
end when
end choose

is that logic correct?
Feb 6 '09 #6
jkmyoung
2,057 Expert 2GB
Does it work if you use nested ifs instead? Or nested ifs in the when?

I really have no idea as to what processes you're using to manufacture the code which manufactures the code.
Feb 12 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Shaldaman | last post by:
I have an Access form called "Login". "Command10" is a button on the form and "Text5" is a text field on it. When a user enters a value in the Text5 text field and clicks the button Command10, I...
8
by: arganx | last post by:
The conditional statement "if(j.... always executes regardless of what you enter. BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam) { char buffer=""; GetWindowText(hwnd,buffer,256);...
5
by: Gary Wessle | last post by:
Hi if I have a method like this bool myClass::myMothod(myType& mt, herType ht) throw ( SomeExp ); how can I use it in a conditional statement if ( try {
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
5
by: bamn68 | last post by:
how do i use conditional statement in sql? im using access 2003 as frontend and backend. What would be the SQL statement for the situation below? I would like to count the number of records in...
0
by: cljordan | last post by:
I am trying to create a database that list materials and their quantities, and highlights quantities that come up outside a certain percentage range against the average. I have tried the following...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.