This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]