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: -
<root>
-
<ObjectTemplate>
-
<NodeType1></NodeType1>
-
<NodeType2></NodeType2>
-
</ObjectTemplate>
-
<Object>
-
<NodeType1>N11</NodeType1>
-
<NodeType2>N12</NodeType2>
-
</Object>
-
<Object>
-
<NodeType1>N21</NodeType1>
-
<NodeType2>N22</NodeType2>
-
</Object>
-
</root>
-
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. -
<xsl:for-each select="/root/ObjectTemplate/*">
-
<xsl:element name="select">
-
<xsl:variable name="myNodeType"><xsl:value-of select="name(.)"/></xsl:variable>
-
<xsl:for-each select="concat('/root/Object/',$myNodeType)">
-
<xsl:element name="option"><xsl:value-of select="."/></xsl:element>
-
</xsl:for-each>
-
</xsl:element>
-
</xsl:for-each>
-
Line 4 is probably what is wrong in my approach. Any help in this regard is welcome.
Thanks in advance,
Parag
5 7131 jkmyoung 2,057
Recognized Expert Top Contributor -
<xsl:for-each select="/root/ObjectTemplate/*">
-
<xsl:element name="select">
-
<xsl:variable name="myNodeType"><xsl:value-of select="name(.)"/></xsl:variable>
-
<xsl:for-each select="/root/Object/*[local-name()=$myNodeType]">
-
<xsl:element name="option"><xsl:value-of select="."/></xsl:element>
-
</xsl:for-each>
-
</xsl:element>
-
</xsl:for-each>
-
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
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: -
<root>
-
<ObjectTemplate>
-
<NodeType1></NodeType1>
-
<NodeType2></NodeType2>
-
</ObjectTemplate>
-
<Object>
-
<NodeType1>N11</NodeType1>
-
<NodeType2>N12</NodeType2>
-
</Object>
-
<Object>
-
<NodeType1>N21</NodeType1>
-
<NodeType2>N22</NodeType2>
-
</Object>
-
<Object>
-
<NodeType1>N11</NodeType1>
-
<NodeType2>N22</NodeType2>
-
</Object>
-
</root>
-
The XSL I was trying to use: -
<xsl:for-each select="/root/ObjectTemplate/*">
-
<xsl:element name="select">
-
<xsl:variable name="myNodeType"><xsl:value-of select="name(.)"/></xsl:variable>
-
<xsl:for-each select="/root/Object/*[local-name()=$myNodeType and not(.=preceding::$myNodeType)]">
-
<xsl:element name="option"><xsl:value-of select="."/></xsl:element>
-
</xsl:for-each>
-
</xsl:element>
-
</xsl:for-each>
-
I also tried - <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
jkmyoung 2,057
Recognized Expert Top Contributor
Close: -
<xsl:for-each select="/root/Object/*[local-name()=$myNodeType and not(.=preceding::*[local-name()=$myNodeType])]">
-
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.
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".
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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?
|
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 changed to
be like:
|
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
fields from a *single* record from a table called 'Locations' and then
apply one of these field's values...
|
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 command buttons named
"Select All" and "Deselect All". The Onclick property of these buttons runs
code...
| |
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
|
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
|
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 param is always empty (0 nodes selected).
I am trying to figure what the original author of the...
|
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
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |