Subject: Re: Re: [xsl] Doubled output of text nodes From: "Charles Knell" <cknell@xxxxxxxxxx> Date: Fri, 12 Jul 2002 08:28:50 -0700 |
My problem involved recursively invoking a template to process a nested set of elements with the same tag name. It doesn't apply in your situation. I did look over your stuff and I've simplified your HTML and XSLT so that I believe what I've done contains the kernel of a fix for your issue. You'll have to add back the complexity to see if I missed something important. I had not worked with <xsl:key> or the key() function before, so this was a valuable experience for me. I hope the following will be valuable to you, too. ######################################## The simplified HTML: <html> <body> <form method="POST" action="urlToInvoke"> <p>Specify your music preferences (check all that apply):</p> <p><input type="checkbox" name="musicpref_rnb" checked="checked" />R&B<br /> <input type="checkbox" name="musicpref_jazz" checked="checked" />Jazz<br /> <input type="checkbox" name="musicpref_blues" />Blues<br /> <input type="checkbox" name="musicpref_newage" />New Age</p> <p>Choose a Category of Room:</p> <div style="margin-left: 2em"> <input type="radio" name="category" value="liv" checked="checked" /> Living<br /> <input type="radio" name="category" value="din" /> Dining<br /> <input type="radio" name="category" value="bed" /> Bedroom </div> </form> </body> </html> ######################################## The simplifed XSLT: <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="yes" encoding="UTF-8" /> <xsl:key name="rtl" match="input[@type='radio']" use="@name" /> <xsl:template match="div"> <xsl:variable name="name" select="key('rtl', 'category')[position()=1]/@name" /> <select name="{$name}"> <xsl:for-each select="key('rtl', 'category')"> <option value="{@value}"> <xsl:value-of select="following-sibling::text()"/> </option> </xsl:for-each> </select> </xsl:template> </xsl:stylesheet> ######################################## The output: Specify your music preferences (check all that apply): R&B Jazz Blues New Age Choose a Category of Room: <select name="category"> <option value="liv"> Living</option> <option value="din"> Dining</option> <option value="bed"> Bedroom</option> </select> -- Charles Knell cknell@xxxxxxxxxx - email ---- "ashu t" <aashut@xxxxxxxxxxxxxx> wrote: > could you please give the solution what you have found in the book > > as i have the same problem of doubled output > i have a html file which has > <form method="POST" action="urlToInvoke"> > <p>Specify your music preferences (check all that apply):</p> > > <p><input type="checkbox" name="musicpref_rnb" > checked="checked" />R&B<br /> > <input type="checkbox" name="musicpref_jazz" > checked="checked" />Jazz<br /> > <input type="checkbox" name="musicpref_blues" />Blues<br /> > <input type="checkbox" name="musicpref_newage" />New Age</p> > > <p>Choose a Category of Room:</p> > > <div style="margin-left: 2em"><input type="radio" > name="category" > value="liv" checked="checked" /> Living<br /> > <input type="radio" name="category" value="din" /> Dining<br > /> > <input type="radio" name="category" value="bed" /> > Bedroom</div> > </form> > > when i am using this style sheet > <xsl:template match="font/input | form/input | td/input | p/input > | div/input | center/input | table/input"> > <xsl:choose> > <xsl:when test="@type='text' or @type='password'"> > <input name="{@name}" type="{@type}"> > <xsl:apply-templates/> > </input> > </xsl:when> > <xsl:when test="@type='radio' and count( . | key('radios', > @name)[1] ) = 1"> > <select name="{@name}"> > > <xsl:for-each select="key('radios', @name)"> > <option value="{@value}"> > <xsl:value-of select="following-sibling::text()"/> > </option> > </xsl:for-each> > </select> > </xsl:when> > > <xsl:when test="@type='checkbox'"> > <select name="{@name}" multiple="true"> > <xsl:if test="@checked='checked'"> > <xsl:attribute name="ivalue">1</xsl:attribute> > </xsl:if> > <option value="{@value}"> > <xsl:value-of select="following-sibling::text()"/> > </option> > </select> > </xsl:when> > > </xsl:choose> > </xsl:template> > > <xsl:template match="p/form | div/form | center/form | a/form | > table/form | tr/form | td/form | th/form | select/form | ul/form | > > li/form"> > <xsl:apply-templates/> > </xsl:template> > > it is producing out put like this > <p> > Specify your music preferences (check all that apply): > > <select name="musicpref_rnb" multiple="true" ivalue="1"><option > value="">R&B</option></select>R&B<br/> > <select name="musicpref_jazz" multiple="true" ivalue="1"><option > value="">Jazz</option></select>Jazz<br/> > <select name="musicpref_blues" multiple="true"><option > value="">Blues</option></select>Blues<br/> > <select name="musicpref_newage" multiple="true"><option > value="">New Age</option></select>New Age > > Choose a Category of Room: > > <select name="category"><option value="liv"> > Living</option><option value="din"> Dining</option><option > value="bed"> Bedroom</option></select> Living<br/> > Dining<br/> > Bedroom > </p> > but i need output only between <option>and </option> > may be it is being processed two times one by code in tempplate > match ="input" and one by <apply-templates> in template > match="form" if i remove this line > <xsl:value-of select="following-sibling::text()"/> > text is not coming between <option> and </option> which is > required > can you help me > ashu > _________________________________________________________ > There is always a better job for you at Monsterindia.com. > Go now http://monsterindia.rediff.com/jobs > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Re: [xsl] Doubled output of tex, ashu t | Thread | Re: Re: Re: [xsl] Doubled output of, ashu t |
[xsl] XML to plain text : which pro, bruno . o . faure | Date | [xsl] grouping consecutive elements, Arregi Iparragirre. |
Month |