xsl-list
[Top] [All Lists]

Re: testing element's contents

2002-10-03 12:40:46
So a text node in a <Caption> element shell not cause a <p> in the output? Ok, no problem, only the XPath becomes more and more complex:

test="descendant::*[not(self::Link or self::Media or self::Caption)]
      |
      descendant::text()[normalize-space()][not(parent::Caption)]]"

This tests now whether

a descendant element exists, which is not Link, Media or Caption
or
a text node containing non-whitespace characters, which has not Caption as parent.

| is the union operator, which unions the two node sets descendant::* and descendant::text(). If the union is not empty, the test is passed.

Regards,

Joerg


Nathan Shaw wrote:
Joerg,

Thanks. Very close now...

The only thing causing a problem now is that a Media
element can contain two child elements, Link and/or
Caption. I actually had a Link element outside of a
Media element before, but that *SHOULD* not happen.
Both the Link and Caption elements contain text nodes.
So, something like this:

<p>
   <Media type="image" id="1"
file="http://www.mylocal.gov/images/aero.gif";
width="54" height="54" border="" alt="Picture of the
shuttle parachute.">
      <Link url="mytestfile.htm" type="external"/>
      <Caption align="bottom">Picture of the shuttle
parachute.</Caption>
   </Media>
</p>

will pass the test even though it is only an image.

Sorry I left that out. That is the only snag left
preventing your solution from working.

I tried adding to it myself, but I just do not
understand axis conditionals well enough.

<xsl:when
test="descendant::node()[normalize-space()][not(self::Media
or descendant::Link or descendant::Caption)]">
   <p><xsl:apply-templates/></p>
</xsl:when>

--nate


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