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

<Need Help>How to select tagvalues based on multiple conditions in XSLT?

17
Hi,
I have a query regarding the selection of a particular tag based on a condition.
In the following XML code:

Expand|Select|Wrap|Line Numbers
  1.  <root>
  2.  
  3.  <template1>
  4.  <elem1>1000</elem1>
  5.  <elem2>
  6.  <subelem1>65</subelem1>
  7.  </elem2>
  8.  </template1>
  9.  
  10.  <template1>
  11.  <elem1>2000</elem1>
  12.  <elem2>
  13.  <subelem1>45</subelem1>
  14.  </elem2>
  15.  </template1>
  16.  
  17.  <template2>
  18.  <type1>
  19.  <tag1>1000</tag1>
  20.  </type1>
  21.  
  22.  <rule>
  23.     <match>
  24.        <id>10</id>
  25.     </match>
  26.     <tag1> 1000 </tag1>
  27.  </rule>
  28.  
  29.  <rule>
  30.     <match>
  31.        <id>20</id>
  32.     </match>
  33.     <tag1>1000</tag1>
  34.  </rule>
  35.  
  36.  </template2>
  37.   </root>
  38.  
  39.  
Using XSLT,I want to allow all the /root/template2/rule/match/id= only 10 or 30 where /root/template2/rule/tag1 = /root/template2/type1/tag1 and /root/template1/elem1 = /root/template2/type1/tag1 whose /root/template1/elem2/subelem1 > 50

For the above code,error has to be thrown because /root/template2/rule/match/id = 20 whose tag1=1000 and there is a template1 whose elem1=1000 and whose subelem1 is 65(which is >50)

Please let me know the XSLT piece of code how to achieve this conditional selection

Thanks,
Oct 21 '08 #1
2 3147
jkmyoung
2,057 Expert 2GB
So just to be clear, the subelem1 in template1 have to match a given template2 if there is a rule for the elem1? Also, do you use template2/type1/tag1 for the match or template2/rule/match/tag1 for the match?
Does the >50 matter?

Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="/root/template1">
  2.    <xsl:variable name="elem1" select="elem1"/>
  3.   <xsl:variable name="subelem1" select="elem2/subelem1"/>
  4.   <xsl:if test="/root/template2/type1/tag1[.=$elem1]">
  5.      <xsl:if test="not(/root/template2[type1/tag1.=$elem1]/rule/match[id = $subelem1]">
  6.       THROW ERROR HERE.
  7.      </xsl:if>
  8.   </xsl:if>
  9. </xsl:for-each>
  10.  
Oct 21 '08 #2
Dormilich
8,658 Expert Mod 8TB
Hey njsimha,

from your previous thread you should have already learned how to address the most of your conditions.

just to remember, you can put any number of conditions on an XPath:
Expand|Select|Wrap|Line Numbers
  1. element[expr1 = x][expr2 != y][expr3[condition] = z]
regards
Oct 21 '08 #3

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

Similar topics

31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
1
by: Chuck | last post by:
I have a question tht I'm sure someone out there can answer. A friend of mine has developed an Access application that is a very business specific (niche type of application). The application...
2
by: Chuck | last post by:
I am trying to retrive one field from the "company info" table that contains several fields but I want the "company name" field. There is only one record in this table. When I entered the code...
1
by: Chuck | last post by:
I appreciate any help!!! I have an application that has 4 different forms that display the same information except for the fact that they are fed from 4 different parameter queries. The 4...
3
by: WØCBF | last post by:
I know this code has worked before but now appears to get a compile error. The code it seems to choke on line 12. I receive the following message and it highlights the "rst!" statement. Error...
1
by: WØCBF | last post by:
Greetings, I have a form that is bound to a table that has about 15 fields in it and all of the fields are displayed on the main form. I have 4 fields that will be updated and I want to write...
3
by: ALKASER266 | last post by:
Hey guyz I am a java beginner and I have problem with part of the code. The thing that I don't know how to do it in this code is how to show the user that he/she has input an invalid input In my...
5
by: njsimha | last post by:
Hi, In the folowing XML snippet: <template1> <name>student</name> <elem1> <subelem1>65</subelem1> <subelem2>15</subelem2> </elem1>
16
by: njsimha | last post by:
Hi, I have the following XML snippet: <root> <template1> <elem1>1000</elem1> <elem2> <subelem1>65</subelem1>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.