XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old October 16th, 2003, 04:30 PM
chainsmoker chainsmoker is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 8 chainsmoker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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]

Reply With Quote
  #2  
Old October 22nd, 2003, 08:24 AM
imbrokn imbrokn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Location: NJ
Posts: 428 imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 34 m 8 sec
Reputation Power: 10
Send a message via AIM to imbrokn
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

Reply With Quote
  #3  
Old October 22nd, 2003, 08:36 AM
chainsmoker chainsmoker is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 8 chainsmoker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL transformation question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway