This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Re: Getting desired node on template match
- From: "alex ek" <alexek at rediffmail dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: 9 Sep 2002 09:01:08 -0000
- Subject: Re: Re: [xsl] Getting desired node on template match
- Reply-to: xsl-list at lists dot mulberrytech dot com
Thanks
I tried that it is working but not fully.
I did not get why you put //input though it is working .I changed
it to /input still it is working.
As you have said it was picking every input type including
"submit" .so I put a condition and then it was working but then I
added one form and do not know why it is not working.
here is my HTML piece. for first form it is working quite nice but
for other form (It is directly from Google page) it is not
working. do not know why ????????
<form action="some.href" method="get">Login<input type="text"
name="name" /><br />
Password<input type="password" name="password" /><br />
<input type="checkbox" name="checkbox1" value="" />India<br />
<input type="checkbox" name="checkbox2" value="" />Canada<br
/>
<input type="checkbox" name="checkbox3" value="" />England<br
/>
<input type="submit" value="Save Preferences" name="submit"
/></form>
<form action="/search" name="f">
<table cellspacing="0" cellpadding="0">
<tr>
<td width="75"></td>
<td align="center">
<input type="hidden" name="hl" value="en" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="hidden" name="oe" value="UTF-8" />
<input maxlength="256" size="55" name="q" value="" /><br />
<input type="submit" value="Google Search" name="btnG" />
<input type="submit" value="I'm Feeling Lucky" name="btnI"
/></td>
<td valign="top" nowrap="nowrap"><font size="-2">
<a href="/advanced_search?hl=en">AdvancedSearch</a><br />
<a href="/preferences?hl=en">Preferences</a><br />
<a href="/language_tools?hl=en">Language Tools</a></font> </td>
</tr>
</table>
</form>
here is my xsl
<xsl:template match="input[@type='submit']">
<do type ="accept" label="submit">
<go href="ancestor::form[1][{@action}]"> <!--HERE I ACTUALLY
WANT TO TAKE THE VALUE OF ACTION ATTRIBUTE OF FORM FOR HREF AND
METHOD FROM METHOD OF FORM (initially tried for action only)BUT
NOT GETTING HOW TO RETRIVE THAT -->
<xsl:for-each select="ancestor::form[1]/input">
<xsl:if test="@type='text' or @type='password' or
@type='checkbox'">
<postfield name="{@name}" value="${@name}"/>
</xsl:if>
<xsl:if test="@type='hidden'"> <!-- initially i had put
every condition (type=hidden ,type='')in one that is above but
that was giving error so i tried to write it -->
<postfield name="{@name}" value="${@name}"/>
</xsl:if>
<xsl:if test="not(@type)"> <!-- this is for if type is
not given as in google then take it as type = text so name value
pair for that -->
<postfield name="{@name}" value="${@name}" />
</xsl:if>
</xsl:for-each>
</go>
</do>
</xsl:template>
the output it is giving (WML)
this is just a portion
<do type="accept" label="submit">
<go href="ancestor::form[1][]">
<postfield name="name" value="$name"/>
<postfield name="password" value="$password"/>
<postfield name="checkbox1" value="$checkbox1"/>
<postfield name="checkbox2" value="$checkbox2"/>
<postfield name="checkbox3" value="$checkbox3"/>
</go>
</do>
<input name="q" type="text"/><br/><!-- this is conversion of input
type ='' in type =text for input type in google -->
<do type="accept" label="submit">
<go href="ancestor::form[1][]"/>
</do>
<do type="accept" label="submit">
<go href="ancestor::form[1] []"/>
</do>
Why it is giving this output though it is giving correct for first
form.
And what i want is to do same thing with input type="radio" but in
radio every one has same name so i want to make only one
<postfield name="" value="">.
It can be done by grouping as i have solved for conversion of
input type
radio . but i have sen that code on
http://www.jenitennison.com/xslt/grouping/muenchian.xml
so i put that .it is working but i did not get its meaning .
i have declared a key
<xsl:key name="rad" match="input[@type='radio']" use="@name"/>
then one condition in template match=input
<xsl:when test="@type='radio' and count( . | key('rad', @name)[1]
) = 1">
but i did not get what this condition is doing
I understood . is the current node and taking its union with
?????? confused ......
can you tell me
alexek
I'm not quite sure what you mean, perhaps
<xsl:template match="input[@type='submit']">
<xsl:for-each select="ancestor::form[1]//input>
<xsl:value-of select="@name"/>
<xsl:value-of select="@value"/>
</xsl:for-each>
</xsl:template>
This gets the nearest form ancestor of the matched input
field and uses all descendent inputs, including the matched.
Be careful if you have
- nested forms
- multiple submits per form
J.Pietschmann
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list