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

Re: select name of element / deal with embedded for-ea

Subject: Re: select name of element / deal with embedded for-each
From: Niclas Hedhman <niclas@xxxxxxxxxxx>
Date: Sun, 30 May 2004 06:27:12 +0800
xsl value of select name
Hi,

Forget <xsl:for-each>, you rarely need it.

The following templates should work. Note the 'double-slash', which means "any 
descendants at any level below".


<xsl:template match="SOURCES" >
  <html>
    <body>
      <table>
        <tr>
          <td>INDEX_A</td>
          <xsl:apply-templates select="SOURCE//INDEX_A" />
        </tr>
        <tr>
          <td>INDEX_B</td>
          <xsl:apply-templates select="SOURCE//INDEX_B" />
        </tr>
        <tr>
          <td>INDEX_C</td>
          <xsl:apply-templates select="SOURCE//INDEX_C" />
        </tr>
      </table>
    </body>
  </html>
</xsl:template>

<xsl:template match="INDEX_A" >
  <td>
    <xsl:value-of select="." />
  </td>
</xsl:template>

<xsl:template match="INDEX_B" >
  <td>
    <xsl:value-of select="." />
  </td>
</xsl:template>

<xsl:template match="INDEX_C" >
  <td>
    <xsl:value-of select="." />
  </td>
</xsl:template>


Cheers
Niclas


On Sunday 30 May 2004 05:59, Xyan wrote:
> Hi,
>
> as a beginner, I try to transform an XML structure like this one :
>
> <SOURCES>
>     <SOURCE CODE="SOURCE_1">
>             <INDEX>
>                 <INDEX_A>A1</INDEX_A>
>                 <INDEX_B>B1</INDEX_B>
>                 <INDEX_C>C1</INDEX_C>
>             </INDEX>
>     </SOURCE>
>     <SOURCE CODE="SOURCE_2">
>             <INDEX>
>                <INDEX_A>A2</INDEX_A>
>                 <INDEX_B>B2</INDEX_B>
>                 <INDEX_C>C2</INDEX_C>
>             </INDEX>
>     </SOURCE>
>
>
> into an HTML table :
>
> <html>
> <body>
> <table>
> <tr>
> <td>INDEX_A</td>
> <td>A1</td>
> <td>A2</td>
> </tr>
> <tr>
> <td>INDEX_B</td>
> <td>B1</td>
> <td>B2</td>
> </tr>
> <tr>
> <td>INDEX_C</td>
> <td>C1</td>
> <td>C2</td>
> </tr>
> </table>
> </body>
> </html>
>
> I have two difficulties :
> 1. How to select the name of an element (in my case : <INDEX_A>  must
> become : <td>INDEX_A</td> ).
> 2. How to write the xslt in order to treat /at once/ EACH INDEX FOR EACH
> SOURCE. I have some difficulties because of the two xsl:for-each that
> must coexist.
>
>
> I have tried :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>     <xsl:output method="html"/>
>     <xsl:template match="/">
>         <html>
>             <body>
>                 <table border="1">
>                     <xsl:for-each select="/SOURCES/SOURCE[1]/INDEX/*">
>                         <tr>
>                             <xsl:for-each select="/SOURCES/SOURCE">
>                                 <td>
>                                     <xsl:value-of select="INDEX/*"/>
>                                 </td>
>                             </xsl:for-each>
>                         </tr>
>                     </xsl:for-each>
>                 </table>
>             </body>
>         </html>
>     </xsl:template>
> </xsl:stylesheet>
>
> but the result :
>
> A1 	A2
> A1 	A2
> A1 	A2
>
>
> is, as you see and have guessed, bad.........
>
> Thanks a lot for your help.
>
> Xyan

-- 
   +------//-------------------+
  / http://www.bali.ac        /
 / http://niclas.hedhman.org / 
+------//-------------------+

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.