469,326 Members | 1,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

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 26052
Dormilich
8,651 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

Post your reply

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

Similar topics

7 posts views Thread by Shaldaman | last post: by
8 posts views Thread by arganx | last post: by
5 posts views Thread by Gary Wessle | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.