Re: Mixed content: selecting current context w/out child

Subject: Re: Mixed content: selecting current context w/out child
From: "John E. Simpson" <simpson@xxxxxxxxxxx>
Date: Sat, 13 Mar 1999 12:12:17 -0500
I asked the list a bit ago:

>This has got to be a fairly elementary question.... What's the proper
select expression to retrieve *only* the PCDATA portion of a mixed-content
element, *not* the contents of its children?

As a member of the list kindly reminded me off-list, the answer is to use
one or more text() nodes.

Given:
    <name>Candace Hilligoss<role>Mary Henry</role></name>
to produce the following HTML:
    <tr>
      <td>Candace Hilligoss</td>
      <td>Mary Henry</td>
    </tr>
use:
    <xsl:for-each select="name">
      <tr>
         <td><xsl:value-of select="text()"/></td>
	   <td><xsl:value-of select="./role"/></td>
      </tr>
    </xsl:for-each>
The text() gets just the first PCDATA portion of the <name> element. If
there were more than one, I could get them all by replacing the first
value-of with a nested for-each, like so:
    <xsl:for-each select="name">
      <tr>
	    <xsl:for-each select="text()">
      	  <td><xsl:value-of select="."/></td>
	    </xsl:for-each>
	   <td><xsl:value-of select="./role"/></td>
	</tr>
    </xsl:for-each>

<slappingforehead/>

Thanks!

==========================================================
John E. Simpson            | The secret of eternal youth
simpson@xxxxxxxxxxx        | is arrested development.
http://www.flixml.org      |  -- Alice Roosevelt Longworth


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


Current Thread