[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: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Thu, 3 Oct 2002 16:54:57 +0100
xsl when test element exists
Couldn't you just count the number of child nodes (including text()) and
then test for img/a?

something like:

<xsl:choose>
  <xsl:when test="count(child::node()) = 1 and (child::img or
child::a)">
    <xsl:copy-of select="child::*"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:copy-of select="."/>
  </xsl:otherwise>
</xsl:choose>

cheers
andrew 

> -----Original Message-----
> From: Nathan Shaw [mailto:n8_shaw@xxxxxxxxx]
> Sent: 03 October 2002 16:08
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  testing element's contents
> 
> 
> hi all,
> 
> Thanks to everyone who gave me advice on my previous
> post about images and captions. Now, I have another
> 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 (read,
> no other nodes, be they text or not), such as:
> 
> <p><img
> src="http://www.mylocal.gov/images/nasausa.gif"
> height="255" width="432"/></p>
> 
> I need to strip the p tags out of resulting output.
> 
> However, if it does contain other nodes, such as:
> 
> <p><img
> src="http://www.mylocal.gov/images/nasausa.gif"
> height="255" width="432"/>This is my news release. The
> 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 we?
> 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 a
> text node after a media or link element.
> 
> <xsl:template match="p">
> <xsl:choose>
> 	<xsl:when test="((descendant::*[1])[self::Link] and
> (descendant::*[2])[self::Media]) or
> (descendant::*[1])[self::Media]"><xsl:apply-templates
> /></xsl:when>
> 	<xsl:otherwise><p><xsl:apply-templates
> /></p></xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> 
> Thoughts? Ideas? Criticisms?
> 
> --nate
> 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> New DSL Internet Access from SBC & Yahoo!
> http://sbc.yahoo.com
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.393 / Virus Database: 223 - Release Date: 30/09/2002
>  
> 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.393 / Virus Database: 223 - Release Date: 30/09/2002
 

 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.