 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 6th, 2006, 10:45 PM
|
|
Registered User
|
|
Join Date: Sep 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Help : combobox in xsl to select value by default
<xsl:variable name="cmbDefault" select="U"></xsl:variable>
<SELECT id="cmbAction" name="cmbAction">
<xsl:element name="OPTION">
<xsl:if test="A = $cmbDefault">
<xsl:attribute name="selected" />
</xsl:if> L </xsl:element>
<xsl:element name="OPTION">
<xsl:if test="A = $cmbDefault">
<xsl:attribute name="selected" />
</xsl:if> U </xsl:element>
<xsl:element name="OPTION">
<xsl:if test="A = $cmbDefault">
<xsl:attribute name="selected" />
</xsl:if> N </xsl:element>
<xsl:element name="OPTION">
<xsl:if test="A = $cmbDefault">
<xsl:attribute name="selected" />
</xsl:if> F </xsl:element>
<xsl:element name="OPTION">
<xsl:if test="A = $cmbDefault">
<xsl:attribute name="selected" />
</xsl:if> I </xsl:element>
</SELECT>
I am using above code to select the default value in the combobox.
But its not working.. I am getting only the combobox with options listed. but its not selecting the default value..
Please help..
|
|

September 7th, 2006, 01:55 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
The correct way to set the "selected" attribute is
<xsl:attribute name="selected">selected</xsl:attribute>
(the HTML syntax is an SGML shortcut for selected="selected").
I don't know what "A" is in:
<xsl:if test="A = $cmbDefault">
Perhaps you meant a string literal, test="'A' = $cmbDefault", I've no idea what your input is. But whatever it is, you're using the same test for each option, so either they will all be selected or none of them will be selected, which seems quite wrong.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

September 7th, 2006, 02:37 AM
|
|
Registered User
|
|
Join Date: Sep 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<xsl:variable name="cmbDefault"
select="'<xsl:value-of select="A"/>'">
</xsl:variable>
<SELECT id="cmbAction" name="cmbAction">
<xsl:element name="OPTION">
<xsl:if test="'L' = $cmbDefault">
<xsl:attribute name="selected" />
</xsl:if> L </xsl:element>
<xsl:element name="OPTION">
<xsl:if test="'U' = $cmbDefault">
<xsl:attribute name="selected" />
</xsl:if> U </xsl:element>
<xsl:element name="OPTION">
<xsl:if test="'N' = $cmbDefault">
<xsl:attribute name="selected" />
</xsl:if> N </xsl:element>
<xsl:element name="OPTION">
<xsl:if test="'F' = $cmbDefault">
<xsl:attribute name="selected" />
</xsl:if> F </xsl:element>
<xsl:element name="OPTION">
<xsl:if test="'I' = $cmbDefault">
<xsl:attribute name="selected" />
</xsl:if> I </xsl:element>
</SELECT>
I want L,U,N,F,I VALUES TO BE LISTED ON THE combo box.
Variable cmbDefault will have anyone value among L,U,N,F,I from XML.
So depending on the value in cmbDefault, i want the default value to be set.. Please help..
I am new to XSLT and so if anything not clear plz let me know..
awaiting ur reply.
|
|

September 7th, 2006, 03:15 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
><xsl:variable name="cmbDefault"
select="'<xsl:value-of select="A"/>'"> </xsl:variable>
You're making things absurdly complicated there (And quite incorrect. Why would you want the value of the variable to be the source code of an XSLT instruction?). I'm not sure where the default value comes from in your XML, but you want something like:
<xsl:variable name="cmbDefault" select="A"/>
where "A" should be replaced by a path expression that selects the value.
Also as I said before, use selected="selected".
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

September 7th, 2006, 04:01 AM
|
|
Registered User
|
|
Join Date: Sep 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Excellent mhkay..
Thanks a lot...
I got the answer..
|
|

July 1st, 2008, 02:11 PM
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I want to show a list of item names in a table for any selected item in a combobox. List of items are child element of the selected item in an xml document. I am new creating xsl document and java script. By search on web I am able to load the combo box with items for which I need to create table upon user selection. But unable to create a table for selected item in the combobox.
Can any of you help me on this?. Any sample you might have whould be greatly appreciated.
|
|

July 1st, 2008, 05:25 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I imagine your aim is to achieve this effect using HTML (and not, say, using XForms).
XSLT is used to convert the XML into your target vocabulary, whether that is HTML, XForms, or anything else.
If you know what HTML you want to generate, tell us, and we can help you write the XSLT. If you don't know what HTML you want to generate, then this isn't the place to ask: you have an HTML question and should find a suitable forum for it.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

July 3rd, 2008, 08:37 AM
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
This is what I am doing. I have list of districts and their associated counties in xml document. I was able to display the information in a tabular format on share point, as web part, using the xml and xsl transformation of xml. Now I need to change the way the county information is dispalyed. Instead of a table with a complete list of districts and associated counties, I need to provide
a combo box with all the districts. When the user chooses a district form the combo box, its associated counties information is displayed in a table underneath the combo box. I learnt from, http://aspalliance.com/1067_Creating...d_JavaScript.3, I need to create a div layer to hide counties of each district and display them based user selected county. I am trying to do exactly what the author is trying to do. But, only difference is that I am trying do it using combo box. Let me know if you help me now. I appreciate your response and I hope you could help me as much as you could. If not atleast point me to other sources where I could look for some information. Thanks.
|
|

July 3rd, 2008, 09:05 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Firstly - why are you posting on the end of someone else's question?
Secondly - this is an XSLT forum - if you want help with Javascript and DHTML then I suggest finding a forum on those topics.
If you know what you are trying to output, and can provide us with examples of your input and output then we can help you with the XSLT.
/- Sam Judson : Wrox Technical Editor -/
|
|
 |