473,472 Members | 2,224 Online
Bytes | Software Development & Data Engineering Community
Create 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_unique_time">
<answer question="yourname">FLEB the Amazing</answer>
<answer question="yourquest">To get some decent XHTML</answer>
<answer question="favcolor">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.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Jul 20 '05 #1
2 1460
In article <1e******************************@40tude.net>,
FLEB <so*********@mmers.and.evil.ones.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_unique_time">
<answer question="yourname">FLEB the Amazing</answer>
<answer question="yourquest">To get some decent XHTML</answer>
<answer question="favcolor">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
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'">...
2
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...
14
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...
7
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...
4
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
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...
4
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...
13
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...
3
by: maxin | last post by:
I have a xml file: <E1MBXYI SEGMENT="1"> ... <CHARG>1000024187</CHARG> ... </E1MBXYI> <E1MBXYI SEGMENT="1"> ... <CHARG>1000024187</CHARG>
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...
1
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...
0
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...
0
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...
0
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 ...
0
muto222
php
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.