473,949 Members | 22,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using variables to select nodes by attribute for an XSLT template

Hi, Does anyone know why when I hardcode a literal to filter a subset
of nodes by a particular attribute value, my template processes the
correct subset.

But, when I use a variable that is set to the same value, my template
processes everything in the document.
<root SELCAT='1'>
<skills>
<skill id='1' CAT='1'>English </skill>
<skill id='2' CAT='1'>French</skill>
<skill id='3' CAT='2'>Latin</skill>
</skills>
</root>

<!-- following processes ids 1,2,3 -->
<xsl:template match="/">
<xsl:variable name="selcatego ry" select="//@SELCAT"/>
<xsl:apply-templates select="//skills/skill[@CAT = $selcategory]">
</xsl:apply-templates>

<!-- following processes ONLY ids 1 and 2 -->
<xsl:apply-templates select="//skills/skill[@CAT = '1']">
</xsl:apply-templates>
Aren't these the same?

Oct 19 '06 #1
1 1755

Never mind, I found the problem...the variable $selcategory wasn't
being set correctly because the root node wasn't being matched
properly. The XSLT should be:
<root SELCAT='1'>
<skills>
<skill id='1' CAT='1'>English </skill>
<skill id='2' CAT='1'>French</skill>
<skill id='3' CAT='2'>Latin</skill>
</skills>
</root>
<!-- following processes ids 1,2,3 -->
<xsl:template match="/root">
<xsl:variable name="selcatego ry" select="@SELCAT "/>
<xsl:apply-templates select="//skills/skill[@CAT = $selcategory]">
</xsl:apply-templates>

Oct 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
6098
by: Mark Constant | last post by:
I have a drop-down list now and I got it so when something is selected from the drop down list it calls a JavaScript function. I want it so the value selected from the drop-down list is sent as a parameter to the xslt file. When I select a value from the drop-down list nothing appears. I want just a basic listing of Title, Image, and Description outputed. I have done a basic JavaScript that uses the .write() function and that worked so the...
6
2950
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for this, and came across a problem that I haven't been able to solve elegantly. The problem is to find "linker" vertexes that a pair of verteces from a pre-defined set. For example, if the graph verteces represent cities and edges represent flights...
2
3418
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only happening when I put my XML files and the .xsl files on my ISP's system for my home page. If I try to open the XML files in Netscape 7.0 on my own machine (ie, not on the ISP's system), the pages convert file and the result is displayed in HTML.
3
2487
by: Sandros | last post by:
Background: I'm collecting usability statistics for a group of applications. Each count has the following attributes: date, application, major heading, minor heading, count. My intent is to pull this back as XML and render it in to an HTML table. I have all this working and all the files are below. I would value any feedback. A simple example of the data looks like this:
2
2208
by: Sylvia | last post by:
Hi, I'm trying to render a XML structure to HTML using XSLT. My XML describe the header of a table with a complex and not linear structure. The first row of the header table always contains the ServiceName (attribute name), under I have to show all the other fields with correct structure. Can you help me to write XSLT document? My XML doc:
2
2730
by: Anthony | last post by:
Hi all, i have managed to create an asp.net menu using xml and xslt.. i am now trying to highlite the selected path by sending in the path info and hilite it using an xsl select choose function. My only problem now is to highlight all parent nodes above the one selected. Does anyone have any ideas as to achieve this.. XML DATA ..........................................................
1
1682
by: karthikpv | last post by:
Hi, I am trying to group nodes in a huge xml file by one of the common fields. I have tried using "for-each-group" and "group-by" but am unable to get it working. Here, I have a list of Ports under each DSLAM entry and would hence like to group in a hierarchy all such Ports under each of these DSLAM entries as shown below.
4
21620
by: Hemal Pandya | last post by:
Hello, I am hoping this is a simple question with a straightforward solution. I do not understand xsl much, so I apologize in advance if I am asking a stupid question. Is it possible to write an xsl that changes some attributes when applied to an xml document, while preserving rest of it. Is it possible to write this xsl independently of the structure of the xml document itself, and only depend on the expression that identifies the...
3
3358
by: =?iso-8859-1?q?Christian_R=FChl?= | last post by:
Hi folks! I have a little noob problem here with XSLT. I have a XML file that looks like this: <archiveFiles> <module path="c:/temp/module_m17_blabla.tmp"/> <module path="c:/temp/module_m34_blabla.tmp"/> ... <moduleAddition path="c:/temp/moduleaddition_m17.tmp"/>
0
10170
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, 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...
0
9990
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,...
0
11188
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11359
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,...
0
9903
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7435
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();...
0
6128
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...
2
4545
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3553
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.