[xsl] Passing a node-set as param to script?
Subject: [xsl] Passing a node-set as param to script?|
From: brian ally <brian@xxxxxxxxxxxxxxxx>
Date: Tue, 04 Nov 2003 12:51:03 -0500
I have several xml files which are used to create forms. Each file has a
variable number of sets of questions which, together with their answers,
make up groups of radio buttons in the form.
<question>What is the foo of bar?</question>
<explanation>Some text which is only displayed after submission (once
scoring has been done)</explanation>
output (first time):
<p class="Question">What is the bar of foo?</p>
<input type="radio" name="1" value="a" /> None
<input type="radio" name="1" value="b" /> Fewer
<input type="radio" name="1" value="c" /> More
When submitted, the output still shows the questions, though the choices
change (using modes) to list-items, with styling to show which choice is
correct, what the user chose if incorrect, and a paragraph with the
<explanation> text. Also, if the user submits without completing all of
the questions a message is shown and any radios which were checked must
be displayed as checked.
I'm using the LibXSLT perl module. There is no defined number of
questions between xml files, so a defined number of params is out (and
would be a kludge anyway). What i'm doing is, when the form has been
submitted, i create a string like so: ",1:b,2:a,3:b," etc. and pass it
to the xsl. Then, for each <choice> of a particular <question_set> i can
compare what the user chose to the correct answer:
select="substring-before(substring-after($choices, concat(',', ../@id,
':')), ',')" />
<xsl:variable name="question_id" select="../@id" />
<xsl:variable name="correct_choice" select="string(following::correct)" />
(got this from someone on this list, in fact)
Where $choices is the passed-in string. This works great, and everything
works as it should. But it is a bit inelegant.
What i'd like to be able to do is create a key containing the user's
choices. Where i've gotten to so far is to create a node-set within the
I'm now passing this in as a param. But the spec says that i can't use a
variable inside the match attribute of a key. So, maybe a key is out.
What i'd like to know is, has anyone run into something like this
before? How can i access the passed-in nodes when doing a for-each on my
I've been going through the archives and googling this for a couple of
days now and have found almost nothing about it (the closest was a post
with this same subject line). Am i barking up the wrong tree? :-p Should
i stick with passing the string and parsing that? As i said - it works
great. But i'm new to XSLT and want to push it a bit.
Any suggestions welcome.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list