RE: [xsl] Trying to ignore specific tags with no content

Subject: RE: [xsl] Trying to ignore specific tags with no content
From: "Kelly, Laura (NIH/NLM/NCBI) [E]" <kelly@xxxxxxxxxxxxxxxx>
Date: Thu, 2 Jun 2011 12:36:08 -0400
If your empty tags are truly empty (no nested  empty elements or whitespace),
this should do:

<xsl:template match="strong" mode="inline">
	<xsl:if test="node()">
		 <strong><xsl:apply-templates mode="inline"/></strong>
	</xsl:if>
</xsl:template>

lk

________________________
Laura Kelly
kelly@xxxxxxxxxxxxxxxx
NCBI/NLM/NIH


-----Original Message-----
From: Paul Chernoff [mailto:pchernoff@xxxxxxxxxxxxxxxxx]
Sent: Thursday, June 02, 2011 12:25 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Trying to ignore specific tags with no content

Despite doing XSLT work for the past few years I still feel like a novice. I
have hit the wall on a specific problem which I should think would be easy to
solve.

BACKGROUND
I am processing a XML file that I want to convert to HTML. Everything works
fine unless there is an empty <strong /> tag in it. This happens because the
source document originated from Adobe InCopy and in cutting a pasting a bold
style that is applied to the space between characters is left in the document.
My XSLT ends up creating a <strong /> tag in this case which is disliked by
web browsers, they see this as a "begin strong tag" resulting in bolding that
is never turned off.

My XSLT is taking a intermediary XML file, not the XML generated directly from
InCopy.

MY CODE
When I get to processing the contents of the document I use a bunch of
xsl:template tags. I never know if any paragraphs will have strong, em, or br
tags within it.

Here is a snippet of the XML document being processed:
            <Main_Body>
                <strong>For the Quads</strong>
            </Main_Body>
            <Main_Body>Place one foot on a step or bench so the quadricep is
parallel to the floor.
                Place the Stick on the top of the quadricep and slowly roll it
on top of the muscle
                while applying pressure. Continue rolling for about 30
seconds. Switch legs and
                repeat.</Main_Body>

Here is a snippet of the XSLT code:

	<xsl:template match="SubHead1" mode="inline">
		<h4 class="headline"><xsl:apply-templates mode="inline"/></h4>
	</xsl:template>
	<xsl:template match="SubHead2" mode="inline">
		<h5 class="subheadline"><xsl:apply-templates mode="inline"/></h5>
	</xsl:template>
	<xsl:template match="Main_Body" mode="inline">
			<p><xsl:apply-templates mode="inline"/></p>
	</xsl:template>
	<xsl:template match="strong" mode="inline">
		<strong><xsl:apply-templates mode="inline"/></strong>
	</xsl:template>
	<xsl:template match="em" mode="inline">
		<em><xsl:apply-templates mode="inline"/></em>
	</xsl:template>
	<xsl:template match="a" mode="inline">
		<xsl:copy-of select="." copy-namespaces="no"/>
	</xsl:template>
	<xsl:template match="br" mode="inline">
		<br/>
	</xsl:template>

My problem is that if 'match="strong"' and if the string of the strong tag is
empty, I don't want to generate any results. I have attempted to use the
xsl:if tag but it doesn't work because I am already in the contents of the
<strong> tags. I have been attempting to put in some sort of conditional
statement in the xsl:template when match="strong" to say 'if there is no
content don't do anything'. I just can't think of any way of writing that.

Or perhaps my approach is just wrong.

Paul Chernoff
Director of Information Technology
Washingtonian Magazine

Current Thread