Re: [xsl] Skip Nodes If Condition

Subject: Re: [xsl] Skip Nodes If Condition
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Tue, 25 Jun 2002 23:34:46 +0200
Hello Scott,

what you did in your template, is more or less useless. You do not output label, if it's empty. So you don't need the if-test, because outputting an empty label has the same effect.

You must do it earlier: <xsl:apply-templates select="ad/ad_content[normalize-space(label)]"/>

or you add the if-test around the content of the template:

<xsl:template match="ad_content">
  <xsl:if test="normalize-space(label)">
    <h3>ad_content</h3>
    <xsl:value-of select="label" />
  </xsl:if>
</xsl:template>

A third possibility is to add a third empty template:

<xsl:template match="ad_content[not(normalize-space(label))]"/>

Regards,

Joerg

Scott Purcell wrote:
> Hello,
> I am trying to skip certain nodes if a condition is met.
> I have searched the mailing list, but cannot find a good match for my problem.
> If the ad_content does NOT contain a label, I want to skip it. Is it best to do a "if test" like I did below, or is there a better technique that I need to learn?
>
> Thanks
> Scott
>
> Here is a piece of the xml:
> <ad_content>
> <item_type>hidden</item_type>
> </ad_content>
> <ad_content>
> <label>headline</label>
> <item_type>hidden</item_type>
> </ad_content>
>
> I am sending this to a template match. eg:
> <xsl:apply-templates select="ad/ad_content" />
>
>
> <!-- template -->
> <xsl:template match="ad_content">
> <h3>ad_content</h3>
> <xsl:if test="label[.!='']"> <!-- make sure it is not blank -->
> <xsl:value-of select="label" />
> </xsl:if>




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


Current Thread