473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XSL/XML Select and Option HTML tags

Hi, I'm trying to render tabular data in an HTML document using XSL to
transform XML data into an HTML table. Some of the tabular data
appears as droplists (implemented by the HTML Select and Option tags).
All the droplists have the same option entries that a user can choose
from.

Is there anyway to reuse a single "master" branch in the XML document
that contains all the option entries for all the select droplists in
the XSL document? As there can be hundreds of skills, it wouldn't be
practical to keep repeating the option data as childnodes for each
skill node in the XML document.

The style sheet looks like:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/skills">
<TABLE>
<TR>
<TD>Skill</TD>
<TD>Expertise</TD>
</TR>

<xsl:apply-templates select="*">
</xsl:apply-templates>

</TABLE>
</xsl:template>

<!--END OF STYLE SHEET -->

<xsl:template name="list" match="skill">
<TR>
<TD><!-- skill name -->
<xsl:value-of select="current()" disable-output-escaping="yes"/>
</TD>
<TD<!-- expertise droplist name -->
<SELECT>
<xsl:attribute name="ID"><xsl:value-of
select="concat('expertiseID_',position())"/></xsl:attribute>
<xsl:attribute name="NAME"><xsl:value-of
select="concat('expertiseNAME_',position())"/></xsl:attribute>
<OPTION></OPTION>
</SELECT></TD></TR>
</xsl:template>

</xsl:stylesheet>

Oct 18 '06 #1
3 7319
"Andy" <an****@infotek-consulting.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi, I'm trying to render tabular data in an HTML document using XSL to
transform XML data into an HTML table. Some of the tabular data
appears as droplists (implemented by the HTML Select and Option tags).
All the droplists have the same option entries that a user can choose
from.

Is there anyway to reuse a single "master" branch in the XML document
that contains all the option entries for all the select droplists in
the XSL document? As there can be hundreds of skills, it wouldn't be
practical to keep repeating the option data as childnodes for each
skill node in the XML document.
Why not:

<root>
<skills>
<skill/>
<skill/>
</skills>
<table1><row/><row/></table1>
<table2><row/><row/></table2>
</root>

Alternatively, you can put the skills into a separate document, or into the
stylesheet itself, and reference it with the document() function.

John
Oct 18 '06 #2
Andy wrote:
I'm trying to render tabular data in an HTML document using XSL to
transform XML data into an HTML table. Some of the tabular data
appears as droplists (implemented by the HTML Select and Option tags).
All the droplists have the same option entries that a user can choose
from.

Is there anyway to reuse a single "master" branch in the XML document
that contains all the option entries for all the select droplists in
the XSL document?
There are ways, certainly, you can apply a template several times if
needed for the same input data, you can apply different modes on the
same input data.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 19 '06 #3
Hi John,

I looked into your suggestion for using the document() function, and
this was what I needed! But, instead of calling a seperate XML
document, I redirected the select to a branch in the primary XML
document that contained a list of tags to build the option list from:

I'm posting a condensed version of the code incase anyone else is
looking for how to do this. The code below results in an HTML table of
skills with select boxes to the right of each one:

OUTPUT

English [Fluent ]
French [Working Knowledge ]
Spanish [Weak ]
German [ ]
Italian [ ]
XML DOCUMENT

<root>
<skills>
<skill selstrength='1'>English</skill>
<skill selstrength='2'>French</skill>
<skill selstrength='3'>Spanish</skill>
<skill selstrength='0'>German</skill>
<skill selstrength='0'>Italian</skill>
</skills>
<optionlist>
<strength ID='0'></strength>
<strength ID='1'>Fluent</strength>
<strength ID='2'>Working Knowledge</strength>
<strength ID='3'>Weak</strength>
</optionlist>
<root>
XSLT STYLESHEET

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"<!-- root node of xml document -->
<TABLE>
<TR>
<TD>Skill</TD>
<TD>Expertise</TD>
</TR>
<xsl:apply-templates select="//skills/skill"<!-- for each skill in
the xml document -->
</xsl:apply-templates>
</TABLE>
</xsl:template>

<!--END OF STYLE SHEET -->
<!-- WRITE A LINE FOR A SINGLE SKILL -->
<xsl:template name="list" match="skill">
<xsl:variable name="selstrength" select="@selstrength"/>
<TR>
<TD><!-- SKILL NAME -->
<xsl:value-of select="current()" disable-output-escaping="yes"/>
</TD>
<TD>

<!-- CREATE THE SELECT DROPBOX -->
<SELECT>
<xsl:attribute name="ID"><xsl:value-of
select="concat('SKILL_',position())"/></xsl:attribute>

<xsl:apply-templates select="//optionlist/strength"<!-- create the
options -->
<xsl:with-param name="selstrength" select="$selstrength"/>
</xsl:apply-templates>

</SELECT>

</TD></TR>
</xsl:template>

<!-- CREATE A PAIR OF OPTION TAGS -->
<xsl:template name="options" match="strength">
<xsl:param name="selstrength" />
<xsl:variable name="id" select="@ID"/>
<OPTION>
<xsl:choose>
<xsl:when test="$selstrength=$id">
<xsl:attribute name="SELECTED">SELECTED</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:value-of select="current()" disable-output-escaping="yes"/>
</OPTION>
</xsl:template>
</xsl:stylesheet>

Oct 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stewart | last post by:
Dear comp.lang.javascript, I have more than once wanted to manipulate the contents of select boxes dynamically, whilst the boxes contain <optgroup> tags. Manipulation of a select box containing...
13
by: Oliver Hauger | last post by:
Hello, In my html form I show a select-element and if this element is clicked I fill it per JavaScript/DOM with option-elements. I use the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD...
7
by: skeddy | last post by:
In a nutshell, I'm trying to dynamically create a select box with ResultSet code in vbscript and then need to be able to access the value of that select box later with a Save button. I've got...
4
by: Ian Richardson | last post by:
Hi, The function I've put together below is a rough idea to extend a SELECT list, starting from: <body> <form name="bambam"> <select id="fred"> <option value="1">1</option> <option...
9
chunk1978
by: chunk1978 | last post by:
hey everyone, i've been trying to solve this problem for 2 days straight, with no end in sight. i would greatly appreciate anyone's help. EXPLANATION: There are 3 Select Menus. The 1st and...
0
by: sundsx | last post by:
Hi, i would sen multiple select to mysql by form, my prb is: file connect.php <?php $user="sundsx"; $pass="password"; $db="testphp"; $val_form=$_POST; $service =$_POST;
2
by: Sudhakar | last post by:
i have two select tags as part of a registration form, city1 city2 where city1 has a list of regions and similar for city2 there are different regions for city1 and city2 so instead of all the...
2
by: nixan | last post by:
Hai all im new to this forum and begin to learn php. Here is a problem which may be very simple to you but it is problem to me. how can choose SELECT tag from a form if there are multiple SELECT...
4
by: html | last post by:
Hello all, I need to change the colour of my text. For the paragraph I do document.fgColor ="blue" ; but how do I do this for the select tags? ....and I prefer it to apply to all select tags...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.