|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
XSL transformation question
With the given XML file below I would like to transform to an HTML
select box for each "CurrentAlias" node and give an <option> for all of the choice items in a given CurrentAlias. The XSL file below is what I am using and the select box per "CurrentAlias" works fine but I only get the first choice item in each "CurrentAlias" node as an <option> for each select box. What am I doing wrong? XML file is subject to change as well. XML file <aliases> <CurrentAlias name="FirstName"> <choice>John</choice> <choice>Joh</choice> <choice>Jo</choice> <choice>J</choice> </CurrentAlias> <CurrentAlias name="LastName"> <choice>Smith</choice> <choice>Smit</choice> <choice>Smi</choice> <choice>Sm</choice> <choice>S</choice> </CurrentAlias> </aliases> XSL File <xsl:for-each select="aliases/CurrentAlias"> <select> <xsl:attribute name="name"> <xsl:value-of select="@name" /> </xsl:attribute> <option> <xsl:attribute name="value"> <xsl:value-of select="." /> </xsl:attribute> <xsl:value-of select="." /> </option> </select> </xsl:for-each>[CODE][CODE] |
|
#2
|
|||
|
|||
|
Try this:
Code:
<xsl:stylesheet version="1.0" xslns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="Aliases"/>
</xsl:template>
<xsl:template match="CurrentAlias">
<select>
<xsl:attribute name="Name">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:for-each select="Choice">
<option>
<xsl:attribute name="value">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
</xsl:template>
</xsl:stylesheet>
I haven't tested it but that is the idea anyway. That ought to work for you, just make sure I'm right with my cases, and that I've propery nested all the tags. Though i think I have |
|
#3
|
|||
|
|||
|
Thanks.
I actually worked it out a few days ago. I had not worn my XML/XSLT hat in about a year and it took me a day or two to get back in the groove. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL transformation question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|