Jump to content

Select box in xslt


swati

Recommended Posts

Hi...can u help me...pls see the following code<select name='category' class='text2'><xsl:for-each select="homepage/QuickSearch/salary"><option><xsl:value-of select="name"/></option></xsl:for-each></select>i want to add <xsl:value-of select="name"/> in <option value="">i tried <option value='<xsl:value-of select="name"/>'><xsl:value-of select="name"/></option>but its not working

Link to comment
Share on other sites

When you want to insert a certain XML value inside an attribute, you must always use XSLT variables. I'm starting to wonder why this isn't specified anywhere in the XSLT tutorial(though it exist in the referance), because it's a very frequent issue...Anyway... as I said, use <xsl:variable name="NAME" select="name" /> like this:

<xsl:variable name="NAME" select="name" /><option value='{NAME}'><xsl:value-of select="name"/></option>

Notices for the variable: The lifetime of a variable is considered the element in which is placed. If you place the variable at the top of the document before any templates, the variable will be accesable everywhere. If specified in a template, it will be avaiable only to that template and so on.All variables must have names. They are the only way to acces a variable. The name could be anything you want. It could actually match the XPath expression. In order to show you the difference in using a name and an XPath expression I have made the name different from the expression.The "select" attribute of the variable defines an XPath expression to be selected. It's optional, because a variable could be used for other things, though this is it's most common use(see the referance for details).

Link to comment
Share on other sites

Thanks a lot...it working now...tat was a great help...again thanks a lotactually i m new in XMLCan u do one more help...i want to do this in xml & xslwhile($r1=mysql_fetch_array($r)){ if($i==5){ $i=1; ?></tr> <tr><td ></td></tr> <tr><td></td></tr> <tr> <?php} ?><td class='normal'> <LI><U><?=$r1['fldCategoryName']?></U> </td><?php $i=$i+1;}

Link to comment
Share on other sites

I'm not very experienced at PHP... In fact, I pretty much don't know anything besides the basic syntax. Because of this, I wasn't able to grasp what you want. Could you please explain it in a "human" language or at least give an HTML code(only) and point what, where, when... like "I want the value in the td to have the value of the XML element called 'TDdata'."

Link to comment
Share on other sites

If all td elemtns are placed one by one inside an XML and you want them one by one in the final output, than this is easy:<table><xsl:for-each select="*whereever the td is*"><tr><td><xsl:value-of select="*whereever the td is*" /></td></tr></xsl:for-each></table>Increasing the table columns is somehow harder though. You must either specify the column in which each element should be placed or use some kind of conditional. I'm not sure what expression you should use for a conditional, but solving this "puzzle" is something I want to do for self development, so I'll keep looking. As for specifiying where should each td be on a row:<table><xsl:for-each select="*whereever the td is*"><tr><td> <xsl:value-of select="*whereever the td for the first column is*" /> </td><td> <xsl:value-of select="*whereever the td for the second column is*" /> </td></tr></xsl:for-each></table>

Edited by boen_robot
Link to comment
Share on other sites

well i tried this<tr><xsl:for-each select="homepage/QuickSearch/category"> <xsl:choose><xsl:when test="position() < 5"><td class='normal'><li/><u><xsl:value-of select="name"/></u></td></xsl:when></xsl:choose></xsl:for-each></tr>it is showing first five 5 records,now i want that in<otherwise></otherwise>, i want to again change the value of position() to 1 and close </tr> and open a new <tr>, i tried many times but its not workingDo u have any idea how it will work

Link to comment
Share on other sites

XSLT elements must be properly nested as in all XML based languages. You can't open an "otherwise" element and have it close a tr unless you have opened the tr in the same otherwise OR close the otherwise and place the tr outside of it(which kind'a kills the whole favor).As for this... I'm not sure but have you tryed placing the for-each before the tr... like this:

<xsl:for-each select="homepage/QuickSearch/category"><tr><xsl:choose><xsl:when test="position() < 5"><td class='normal'><li/><u><xsl:value-of select="name"/></u></td></xsl:when></xsl:choose></tr></xsl:for-each>

Or maybe if you add a second conditional with the next five number... only this might get quite messy though:

<tr><xsl:for-each select="homepage/QuickSearch/category"> <xsl:choose><xsl:when test="position() < 5"><td class='normal'><li/><u><xsl:value-of select="name"/></u></td></xsl:when><xsl:when test="position() < 10"><td class='normal'><li/><u><xsl:value-of select="name"/></u></td></xsl:when></xsl:choose></xsl:for-each></tr>

One more thing. Could you give a sample of your XML code, so I can examine the XPaths as well. I think that's the most confusing thing here(for me that is).

Link to comment
Share on other sites

<homepage> <QuickSearch> <category> <name>Accounting/Finance</name> </category> <category> <name>Advertising/Public Relations</name> </category> <category> <name>Arts/Entertainment/Publishing</name> </category> </QuickSearch></homepage>

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...