473,671 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[XSL] Finding "the node with the same @some_attribute value as mine"

Okay, so I've got this XML:

<qa>
<questionset>
<question name="yourname" >What is your name?</question>
<question name="yourquest ">What is your quest?</question>
<question name="favcolor" > What is your favorite color?</question>
</questionset>
<answerset time="some_uniq ue_time">
<answer question="yourn ame">FLEB the Amazing</answer>
<answer question="yourq uest">To get some decent XHTML</answer>
<answer question="favco lor">Dark white</answer>
</answerset>
<!-- more answersets... -->
</qa>

In use, <questionset> is unique to its <qa> container (there may be other
<qa>s, but any given <qa> will have only one <questionset> ). There will,
however, be a lot of different <answerset>s. I want to transform this so I
get the full question with each answer. I just can't think of a way to say
"The question element with the attribute "name", matching THE CURRENT
ELEMENT's "question" value."

I've tried, for instance, looping through the <answer> elements, and using
something like:

<xsl:value-of select="../../questionset/question[@name=@answer]">

but this (as it naturally should) tries to compare the question's @name to
its own @answer. I'm stuck. I also don't want to use IDs in a DTD, because
I might have multiple <questions> with the same id, but under a different
pile of heirarchy. Is there any way to "reset" back to the start of the
path in order to retrieve the current element's @question value? Or (more
likely) am I thinking about this all wrong?

Thanks for any help!

--
-- Rudy Fleminger
-- sp@mmers.and.ev il.ones.will.bo w-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Jul 20 '05 #1
2 1476
In article <1e************ *************** ***@40tude.net> ,
FLEB <so*********@mm ers.and.evil.on es.will.bow-down-to.us> wrote:
<xsl:value-of select="../../questionset/question[@name=@answer]">

but this (as it naturally should) tries to compare the question's @name to
its own @answer.


Use the current() function, e.g. [@name=current()/@answer], or set a
variable to the @answer value outside the <value-xsl:of>.

-- Richard
Jul 20 '05 #2
FLEB the Amazing wrote:
Okay, so I've got this XML:

<qa>
<questionset>
<question name="yourname" >What is your name?</question>
<question name="yourquest ">What is your quest?</question>
<question name="favcolor" > What is your favorite color?</question>
</questionset>
<answerset time="some_uniq ue_time">
<answer question="yourn ame">FLEB the Amazing</answer>
<answer question="yourq uest">To get some decent XHTML</answer>
<answer question="favco lor">Dark white</answer>
</answerset>
<!-- more answersets... -->
</qa>
Interesting problem. I am sorry to say that I have
no solution in XSL (which you were asking for).
But the problem was an interesting exercise for me
to find out where the limits of xmlgawk are.
In use, <questionset> is unique to its <qa> container (there may be other
<qa>s, but any given <qa> will have only one <questionset> ). There will,
however, be a lot of different <answerset>s. I want to transform this so I
get the full question with each answer. I just can't think of a way to say
"The question element with the attribute "name", matching THE CURRENT
ELEMENT's "question" value."


This is the output I get from the attached xmlgawk script:

q: What is your favorite color? a: Dark white
q: What is your name? a: FLEB the Amazing
q: What is your quest? a: To get some decent XHTML
# qa.awk
# comp.text.xml 2004-08-29
# Access to same attribute in different element.
# JK 2004-08-29

BEGIN { XMLMODE=1 }

XMLSTARTELEM == "question" { q=XMLATTR["name"] }
XMLSTARTELEM == "answer" { a=XMLATTR["question"] }

XMLENDELEM { q=a=0 }

XMLCHARDATA && q { qset[q] = $0}
XMLCHARDATA && a { aset[a] = $0}

END {
for (q in qset)
print "q:", qset[q], "a:", aset[q]
}

Jul 20 '05 #3

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

Similar topics

0
1145
by: Simon | last post by:
Hi, I would like to use <xsl:variable> and <xsl:choose> to dynamically set a node-set to a variable. Something like: <xsl:variable name="MyVar"> <xsl:choose> <xsl:when test="$MyVar2='0'"> Here I want to select a node set from the source xml document
2
1520
by: APB | last post by:
I am working on an XSL to transform RSS/RDF feeds into HTML I have come across a bunch of feeds that only have a <description> for each <item> but no <title>. In this event I would like to use the <description> node as if it where the <title> node. I tried something like the following fragment, but it doesn't change anything. How can I obtain what I require while keeping one single universal XSLT? Thanks!
14
12165
by: inquirydog | last post by:
Hi- One frusterating thing for me with xsl is that I don't know how to make xslt throw some sort of exception when a value-of path does not exist. For instance, suppose I have the following line in xslt <xsl:value-of select="/blah/q" /> and my xml document does not have a node /blah/q. The output would
7
2154
by: Scott W Gifford | last post by:
Hello, I'm considering using XML to represent a stream of location information, and XPath to do queries against it. I've got most of it figured out (at least on paper), but I can't figure out how to create an XPath statement asking for the "last node with a value less than" a given value. I need this to be able to ask "Where was Scott at 11:00 yesterday", which should find the last sighting of Scott before or at 11:00
4
1677
by: ina | last post by:
Hello all, I am newbie in xml and have a problem with this parse. I have this xml.file <Style> <Strategy>
0
1964
by: melb | last post by:
I haven't done much work with XSL translations before and i'm stuggling to apply some code to a list of items. The when code works if it is not a list but I think I need to replace the ITEMCOST with something else but i'm not sure what. can someone help. I am using this code as the <xsl:value-of select="format-number does not work with teh translator I'm using. I am basically trying to set the resulting value as two decimal places, for...
4
3913
by: clover2411 | last post by:
Hi there, Apologies if I'm posting to the wrong group; this one looked to be the best match. I'm having trouble writing a bit of XSL/XPATH and wondered if someone would please shed some light. My XML is generated by InfoPath and of the structure: ....
13
1533
by: spicster | last post by:
I need help with finding an entire inventory value for a java assignment. This is what I have so far. I am new to Java and am struggling. In need of help, thanks import java.util.Scanner;//program uses class scanner public class ProductInventory1 {//main method begins java application public static void main (String args)
3
2053
by: maxin | last post by:
I have a xml file: <E1MBXYI SEGMENT="1"> ... <CHARG>1000024187</CHARG> ... </E1MBXYI> <E1MBXYI SEGMENT="1"> ... <CHARG>1000024187</CHARG>
0
8476
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
8914
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8820
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
8598
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
7433
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...
1
6223
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5695
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
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2051
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.