Subject: Re: [xsl] testing element's contents From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 03 Oct 2002 12:04:53 -0400 |
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.
<xsl:template match="p"> <xsl:choose> <xsl:when test="normalize-space(.)"> <!-- this tests true if the paragraph has any string value at all after whitespace normalization. This only occurs if the paragraph or any of its descendants has non-whitespace text content --> <p> <xsl:apply-templates/> </p> </xsl:when> <xsl:otherwise> <xsl:apply-templates/> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template match="p"> <p> <xsl:apply-templates/> </p> </xsl:template>
<xsl:template match="p[not(normalize-space(.))]"> <xsl:apply-templates/> </xsl:template>
Cheers, Wendell
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>
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] representing ampersand an, Vedu Hariths | Thread | Re: [xsl] testing element's content, Nathan Shaw |
RE: [xsl] testing element's content, Andrew Welch | Date | Re: [xsl] testing element's content, Nathan Shaw |
Month |