xsl-list
[Top] [All Lists]

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

2011-06-02 11:36:21
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(_at_)ncbi(_dot_)nlm(_dot_)nih(_dot_)gov
NCBI/NLM/NIH


-----Original Message-----
From: Paul Chernoff [mailto:pchernoff(_at_)washingtonian(_dot_)com] 
Sent: Thursday, June 02, 2011 12:25 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>