Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > [XSL] Finding "the node with the same @some_attribute value as mine"

Reply
Thread Tools

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

 
 
FLEB
Guest
Posts: n/a
 
      08-29-2004
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
--
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      08-29-2004
In article <1ejznzm0mdyld$.x02mq8ibgmi2$.>,
FLEB <> 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-xslf>.

-- Richard
 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?J=FCrgen_Kahrs?=
Guest
Posts: n/a
 
      08-29-2004
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]
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
<need help>How to print the preceding node value based on descendant node in XSLT? njsimha XML 0 09-16-2008 12:33 PM
How to find node in TreeView by using string(the same as Node.Text) ? jiing ASP .Net 0 04-27-2007 02:34 AM
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
Select Node Using position or value of another node. Eddy C XML 6 10-17-2005 11:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57