473,581 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing variable node name to XSL "select" clause

62 New Member
Hello Everyone.
I'm new to XSL and couldn't get something to work. [Not sure if this is the right way to go about it...]
Sample XML excerpt:
Expand|Select|Wrap|Line Numbers
  1. <root>
  2. <ObjectTemplate>
  3. <NodeType1></NodeType1>
  4. <NodeType2></NodeType2>
  5. </ObjectTemplate>
  6. <Object>
  7. <NodeType1>N11</NodeType1>
  8. <NodeType2>N12</NodeType2>
  9. </Object>
  10. <Object>
  11. <NodeType1>N21</NodeType1>
  12. <NodeType2>N22</NodeType2>
  13. </Object>
  14. </root>
  15.  
My intent is to build a list of drop downs (# of drop downs = # of NodeTypes) based on those defined in the template. Using "xsl:for-each" and "xsl:elemen t", I could build 2 drop downs. But I cannot figure out how to pass the select clause a different node type.
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="/root/ObjectTemplate/*">
  2. <xsl:element name="select">
  3. <xsl:variable name="myNodeType"><xsl:value-of select="name(.)"/></xsl:variable>
  4. <xsl:for-each select="concat('/root/Object/',$myNodeType)">
  5. <xsl:element name="option"><xsl:value-of select="."/></xsl:element>
  6. </xsl:for-each>
  7. </xsl:element>
  8. </xsl:for-each>
  9.  
Line 4 is probably what is wrong in my approach. Any help in this regard is welcome.
Thanks in advance,
Parag
Mar 15 '08 #1
5 7127
jkmyoung
2,057 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="/root/ObjectTemplate/*">
  2. <xsl:element name="select">
  3. <xsl:variable name="myNodeType"><xsl:value-of select="name(.)"/></xsl:variable>
  4. <xsl:for-each select="/root/Object/*[local-name()=$myNodeType]">
  5. <xsl:element name="option"><xsl:value-of select="."/></xsl:element>
  6. </xsl:for-each>
  7. </xsl:element>
  8. </xsl:for-each>
  9.  
Mar 17 '08 #2
paragpdoke
62 New Member
Hello jkmyoung.
Thank you very much for the reply. It is working for me.
[Apologies for the delayed response. Somehow instant email notification preference is not working for my thescripts login.]

Regards,
Parag P. Doke
http://paragpdoke.blog spot.com
Mar 21 '08 #3
paragpdoke
62 New Member
I am sorry for reposting. But...my attempts to get only distinct values populated in the drop downs went futile. Here's the new code:
Expand|Select|Wrap|Line Numbers
  1. <root>
  2. <ObjectTemplate>
  3. <NodeType1></NodeType1>
  4. <NodeType2></NodeType2>
  5. </ObjectTemplate>
  6. <Object>
  7. <NodeType1>N11</NodeType1>
  8. <NodeType2>N12</NodeType2>
  9. </Object>
  10. <Object>
  11. <NodeType1>N21</NodeType1>
  12. <NodeType2>N22</NodeType2>
  13. </Object>
  14. <Object>
  15. <NodeType1>N11</NodeType1>
  16. <NodeType2>N22</NodeType2>
  17. </Object>
  18. </root>
  19.  
The XSL I was trying to use:
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="/root/ObjectTemplate/*">
  2. <xsl:element name="select">
  3. <xsl:variable name="myNodeType"><xsl:value-of select="name(.)"/></xsl:variable>
  4. <xsl:for-each select="/root/Object/*[local-name()=$myNodeType and not(.=preceding::$myNodeType)]">
  5. <xsl:element name="option"><xsl:value-of select="."/></xsl:element>
  6. </xsl:for-each>
  7. </xsl:element>
  8. </xsl:for-each>
  9.  
I also tried
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="/root/Object/*[local-name()=$myNodeType and not(.=preceding::local-name(.))]">
...but that too did not work :-(.

How can I get the drop downs to have only distinct values ? [Pardon my lack of knowledge, I have copied the preceding:: thing from elsewhere. Still reading XSL tutorials to get to know more about axes.]

Also, my 2nd question is: What is the difference between local-name() and name() functions ? When I tried using name(), it worked in similar manner.

Someone told me that it made sense to create a DTD file for all possible values instead of generating a list of distinct ones from the data in the XML file. But in this context of building the drop downs and populating them from a DTD, I have more questions:
- How to capture information inside DTD using XSL ?
- How to restrict values of a node to some pre-defined set ? [http://www.thescripts. com/forum/thread785602.ht ml]

Thanks in advance once again,
Parag P. Doke
Mar 22 '08 #4
jkmyoung
2,057 Recognized Expert Top Contributor
Close:
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="/root/Object/*[local-name()=$myNodeType and not(.=preceding::*[local-name()=$myNodeType])]">
  2.  
name() only gives you something different if it has a namespace attached.

For example, take node: <xsl:value-of/>
name is xsl:value-of
local-name is value-of


I'm not really good at DTD, but will have a look at the other question.
Mar 24 '08 #5
paragpdoke
62 New Member
Hi again.
Thank you for the explanation regarding name() and local-name().
Also, if I run into something helpful, I'll make sure I add to this post.

Regards,
Parag P. Doke

P.S.: I guess I should have had the title of this post as "Generating the select clause on the fly" rather than "Passing variable node name to XSL "select" clause".
Mar 25 '08 #6

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

Similar topics

5
11495
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold { CarsSoldID int (primary key) MonthID int DealershipID int NumberCarsSold int
1
5030
by: Son KwonNam | last post by:
When I try <xsl:value-of select="count('/GROUPS/GROUP')"/> on JSTL <x:transform> tag, I got the following error message. org.apache.jasper.JasperException: Can not convert #STRING to a NodeList! but, if I try that on Sonic XIS XSL transform API It works fine. What's the problem? Java(apache JSTL) does not support XPath functions?
10
5601
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I create a single View and specify also in this View the WHERE clause that is common in these stored procedures, I will have the new stored procecures...
1
4165
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two...
6
9325
by: GSteven | last post by:
(as formerly posted to microsoft.public.access.forms with no result) I've created a continuous form which is based on a straightforward table (ex - customers - 100 records). On the form there is a checkbox with a control source named "MARK" (boolean) from customer table. I can check and uncheck individual records fine. Then I created 2...
8
10305
by: Jean | last post by:
Hello all, I have the following data, that was queried and sorted to columns PROBLEM_ID and then by STATUSDATE (ascending): STATUS_ID STATUSDATE PROBLEM_ID --------- ---------- ---------- 10 12/04/2005 1234 40 15/05/2005 1234
2
1463
by: cephelo | last post by:
I have no problems outputting the attribute value when the node is in context, for example, @id when an <status> node is in context. However, I am having trouble outputting it in a <xsl:value-of /> element: <xsl:value-of select="procresults/settings@priority /> where it looks like
2
1878
by: junkblog747 | last post by:
What will the expression "/.." in the attribute select="/.." return? I just inherited a huge stylesheet to maintain which has a lot of parameters such as <xsl:param name="myParam" select="/.."/>. And then there is a lot of conditional processing based on this parameter. I stepped thru the code with a debugger in Oxygen and saw that the...
3
3983
by: yawnmoth | last post by:
//form//input //form//select//option I can combine those with an or (|), but to make my code more concise, would it be possible to reuse the //form bit? Could I maybe do something like this, instead?: //form//(input or select//option) That doesn't work, but is there something similar that would? Or am I
0
7808
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8158
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7917
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8182
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6567
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5685
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1413
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.