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

RE: getting inner elements from a nested for-each?

Subject: RE: getting inner elements from a nested for-each?
From: Jarno.Elovirta@xxxxxxxxx
Date: Thu, 30 Jan 2003 09:39:13 +0200
inner elements
Hi,

>  I'm trying to find the right XSLT to output dataSets
>  into groups associated with a radio button for each
>  set.
>  So, I want to loop over each "dataSet"
>  then loop over the sub-elements contained in there, 
>  in my instance, <Image><Head><subhead>
>  How do I get to Image, Head and subhead ?
> 
>  I've got the following on my XSL:
> 							
> <xsl:variable name="dataSet"
> select="dataSets/dataSet"/>

the dataSet element in the source example below is in namespace "http://ns.adobe.com/GenericCustomNamespace/1.0/", thus you need to declare it in you stylesheet, e.g. as prefix "d", and the above will be

  <xsl:variable name="dataSet" select="dataSets/d:dataSet"/>

>  <xsl:for-each select="$dataSet">
>  <xsl:variable name="current" select="local-name()"/>
>   <tr><td>
> <input type="radio" name="dataSet"
> value="{@dataSetName}"/>
>   </td>
>   <td>
>     <xsl:value-of select="@dataSetName"/>
>    </td>
>    <td>
> <xsl:variable name="innerElement"
> select="$current/*"/>

The variable $current is bound to a string value, thus you can't use it a locations step.

> <xsl:for-each select="$innerElement">
> <xsl:value-of select="."/><BR/>
> </xsl:for-each>
> </td>
> </tr>
> </xsl:for-each>

It this

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:d="http://ns.adobe.com/GenericCustomNamespace/1.0/">

<xsl:template match="/">
  <html>
    <head>
      <title/>
    </head>
    <body>
      <table>
        <tbody>
          <xsl:for-each select="dataSets/d:dataSet">
            <tr>
              <td>
                <input type="radio" name="dataSet" value="{@dataSetName}"/>
              </td>
              <td>
                <xsl:value-of select="@dataSetName"/>
              </td>
              <td>
                <xsl:for-each select="*">
                  <xsl:value-of select="."/>
                  <br/>
                </xsl:for-each>
              </td>
            </tr>
          </xsl:for-each>
        </tbody>
      </table>
    </body>
  </html>
</xsl:template>

</xsl:stylesheet>

What you were after?

Cheers,

Jarno - Wolfsheim: I Don't Love You Anymore

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.