[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

xsl:variable inside xsl:for-each

Subject: xsl:variable inside xsl:for-each
From: "a. benedict balbuena" <abcbalbuena@xxxxxxxxx>
Date: Tue, 11 Apr 2006 17:32:11 +0800
xsl variable inside for each
Hello!

I'm a noob in XSLT and currently using XSLT 1.0. I just learned XSLT
this week and am trying to use it in some of my projects.

I cant seem to find an answer on the net on my problem, maybe some of
you guys can help.

I have an input xml file:

    <ec name="X" value="4"/>
    <ec name="Y" value="7"/>
    <ec name="Z" value="0.1"/>

     <t>
        <p>
            <ec name="sax" value="$X"/>
            <ec name="say" value="$Y"/>
            <ec name="saz" value="$Z"/>
            <t>
                <sxa position="$sax"/>
            </t>
            <t>
                <sya position="$say"/>
            </t>
            <t>
                 <ffA position="$saz"/>
             </t>
         </p>
    </t>


----

I want to output the following in html:

<table border="1">
<tr>
<td>X</td>
<td>4</td>
</tr>

<tr>
<td>Y</td>
<td>7</td>
</tr>
<tr>
<td>Z</td>
<td>7</td>
</tr>
</table>


-----

theoretically the xsl file should do this:

<xsl:for-each select="ec">
<!-- MAKE A VARIABLE NAMED X, Y, and Z -->
</xsl:for-each>

<xsl:for-each select="t/p/ec">
<!-- MAKE A VARIABLE NAMED sax, say, and saz -->
</xsl:for-each>

<table border="1">
     <xsl:for-each select="t/p/t">
         <xsl:choose>
	     <xsl:when test="child::sxa">
                 <tr>
                     <td> <xsl:text> X </xsl:text> </td>
                     <td> <xsl:value-of select="sxa/@position" /> </td>
                 </tr>
             </xsl:when>
	     <xsl:when test="child::sya">
                 <tr>
                     <td> <xsl:text> Y </xsl:text> </td>
                     <td> <xsl:value-of select="sya/@position" /> </td>
                 </tr>
             </xsl:when>

	     <xsl:when test="child::ffa">
                 <tr>
                     <td> <xsl:text> Z </xsl:text> </td>
                     <td> <xsl:value-of select="ffa/@position" /> </td>
                 </tr>
             </xsl:when>
         </xsl:choose>
     </xsl:for-each>
</table>

Im stuck inside the first for-each loops. Inserting the following
inside the for-each loops amounts to nothing since the variable name
should be a string, but i'm really referencing to the name attribute
of the <ec> tag.

<xsl:variable name="@name>
     <xsl:value-of select="@value"/>
<xsl:variable>



Any suggestion will be most welcome! Thanks!

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.