Re: [xsl] making html-form with an identifier in a xsl:for-each

Subject: Re: [xsl] making html-form with an identifier in a xsl:for-each
From: "M. David Peterson" <conners_dad@xxxxxxx>
Date: Sat, 11 Oct 2003 18:22:46 -0600
Hello Nica,

As long as you don't change your context node from 'test' you can simply 
insert the following into your XSLT file between the quotes...

{concat('test_', position())}

or in other words

<input type="text" name="{concat('test_', position())}"/>

Through each iteration through the <xsl:for-each> you will get Test_1, 
Test_2, Test_3 and so forth rendered into your html output.

Keep in mind that the postion() function of XPath is relative to the current 
context node (in this case 'test').  If that changes your position count 
will change.

Best regards,


----- Original Message ----- 
From: "Nica Huestegge" <Nica.H@xxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Saturday, October 11, 2003 5:53 AM
Subject: [xsl] making html-form with an identifier in a xsl:for-each

> Hi!
> I have a little question - probably easy-to-answer, except for a newbie 
> like
> me. I try to describe it as precisely as possible, which makes my mail 
> very
> long. I am sorry, but I dont want to bother you with an unclear question 
> and
> i hope you wont mind the long mail. Thank You.
> I have a number of xml-files which includes something like the following
> (Actually, there is much more stuff around in those files, but I try to 
> keep
> it reduced to my question...):
> <test id="test1">
>   <question>
>     What is five plus four?
>   </question>
>   <answer>
>     nine
>   </answer>
> </test>
> <test id="test2">
>   <question>
>     What is five minus two?
>   </question>
>   <answer>
>     three
>   </answer>
> </test>
> Where the number of <test>-elements varies from file to file.
> I want an output in html, where the question is just text and after every
> question there is a form input for the answer. the whole form will be send
> to a servlet. So the html will look something like this:
> <form method="post" action="NextServlet">
>   <p>
>     What is five plus four?<br/>
>     <input type="text" name="test1"/>
>   </p>
>   <p>
>     What is five minus two?<br/>
>     <input type="text" name="test2"/>
>   </p>
>   <input type="submit"/>
> </form>
> Now, the xsl. I know it has to be something like this:
>             <form method="post" action="NextServlet">
>             <xsl:for-each select="test">
>             <p>
>             <xsl:value-of select="question" /><br/>
>             <input type="text" name="????????"/>
>             </p>
>             </xsl:for-each>
>             <input type="submit"/>
>             </form>
> As you can see, the questionmarks are where my problem is. How can I put a
> unique identifier there (which should equal "test1" or "test2", the id-
> attribute of <test>, so that my Servlet can compare the given answer to 
> that
> in the xml-file?
> Thank you for your time (and answer), sorry for any mistakes (english just
> isnt my language...),
> Nica Huestegge
>  XSL-List info and archive:

 XSL-List info and archive:

Current Thread