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

Re: testing element's contents

Subject: Re: testing element's contents
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Thu, 03 Oct 2002 18:56:04 +0200
xslt element exists
Hi Nathan,

it should work in your example too, because there is a text node as child of the <Link>, so the test is passed.

Only one comment:



The above passes the test because of spaces and line breaks between <p> and <Link> or between <Link> and </Link>. To avoid this you can test on nodes, which don't consist of only whitespaces characters. Use normalize-space() for this (http://www.w3.org/TR/xpath#function-normalize-space):

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

=> If a descendant node exists, that consists not only of whitespace characters, that is not <Link> or <Media>, wrap it in <p>.



Nathan Shaw wrote:
Excellent Joerg! The only place this would not work is
if I have a paragraph element with only a Link element
in it, such as:

<p><Link href="blah.html">This is a link</Link></p>

I need those to pass through the test and be wrapped
in a p tag. Otherwise, it catches everything else I

Thank you! That gives me great direction...


--- Joerg Heinicke <joerg.heinicke@xxxxxx> wrote:

<xsl:when test="descendant::node()[not(self::Link or

If there is any descendant node (including elements,
comments, PIs, text), which is not element Link or element Media,
create <p> in output tree.



Nathan Shaw wrote:

hi all,

Thanks to everyone who gave me advice on my


post about images and captions. Now, I have


tricky lil' xslt problem. If a paragraph element
contains ONLY a media element OR a media element
surrounded by a link element and nothing more


no other nodes, be they text or not), such as:

height="255" width="432"/></p>

I need to strip the p tags out of resulting


However, if it does contain other nodes, such as:

height="255" width="432"/>This is my news release.


authors will be typing the news release content in
here! I am not sure what this news release is even
about, but lets see how it comes out in XML, shall


As I see it coming out as:</p>

I need to leave it alone.

Here is what I have so far. It only looks to see

if a

media element or a media element wrapped by a link
element exists, but does not consider if there is


text node after a media or link element.

<xsl:template match="p">
	<xsl:when test="((descendant::*[1])[self::Link]


(descendant::*[2])[self::Media]) or



Thoughts? Ideas? Criticisms?


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

Current Thread


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.
First Name
Last Name
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.