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

Re: please help: why <xsl:foreach select="node()"> not works

Subject: Re: please help: why <xsl:foreach select="node()"> not works here?
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 24 May 2000 23:48:46 -0600 (MDT)
xsl for each selec
Jia Ming Li,

You didn't mention what XSL processor you are using.

Anyway, consider this part of your XML:

 		<ROW>
 			<A>a1</A>
 			<B>b1</B>
 		</ROW>

It represents this subtree of nodes (note the whitespace, which I write
here as \n for newline and \t for tab):

element 'ROW'
  |
  |___text '\n\t\t\t'
  |
  |___element 'A'
  |     |
  |     |___text 'a1'
  |
  |___text '\n\t\t\t'
  |
  |___element 'B'
  |     |
  |     |___text 'b1'
  |
  |___text '\n\t\t'

In your XSL you say:

 	<xsl:for-each select="ROW">
 		<TR>
 		<xsl:for-each select="node()">

But I think you want:

 	<xsl:for-each select="ROW">
 		<TR>
 		<xsl:for-each select="*">

or even "*/text()" instead of "*".

Also, you may find XSLT to be more powerful if you use a design pattern in
which repetitive processes get their own separate templates, rather than
bloating one template with many xsl:for-each elements. For example:

<xsl:template match="/">
  <HTML>
    <HEAD>
      <TITLE>test</TITLE>
    </HEAD>
    <BODY>
      <xsl:apply-templates select="RESULT/DATA"/>
    </BODY>
  </HTML>
</xsl:template>

<xsl:template match="DATA">
  <TABLE BORDER="2">
    <xsl:apply-templates select="ROW"/>
  </TABLE>
</xsl:template>

<xsl:template match="ROW">
  <TR>
    <xsl:for-each select="*">
      <TD><xsl:value-of select="."/></TD>
    </xsl:for-each>
  </TR>
</xsl:template>

Also take note that ALL CAPITAL LETTERS for the names of HTML elements,
while recommended up through HTML 4.01, is deprecated for XHTML 1.0
and higher.

   - Mike
___________________________________________________________
Mike J. Brown, software engineer, Webb Interactive Services
XML/XSL stuff: http://www.skew.org/    http://www.webb.net/


 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.