Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 26th, 2007, 10:44 AM
Authorized User
 
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl:if problem

how do i set the condition if the child has empty string:

<parent>
  <ch1>
    <data>data1</data>
    <data></data>
    <data>data3</data>
  </ch1>
  <ch1>
    <data>data4</data>
    <data></data>
    <data>data6</data>
  </ch1>
</parent>


 <xsl:for-each select="ch1">
  <xsl:if test="data= '' ">
   <xsl:apply-templates select="data"/>
  </xsl:if>
 </xsl:for-each>

i just want to print <data> tag that has text, if it doesn't contain any, don't print it

how to write the if condition?

 
Old July 26th, 2007, 11:01 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your code is saying "if any of the data elements is equal to "" then apply-templates to all the data elements".

Just replace

 <xsl:for-each select="ch1">
  <xsl:if test="data= '' ">
   <xsl:apply-templates select="data"/>
  </xsl:if>
 </xsl:for-each>

with

<xsl:apply-templates select="ch1/data[string(.)]"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 26th, 2007, 11:29 AM
Authorized User
 
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry my bad,
<xsl:if test="data= '' ">
that line should be
<xsl:if test="data != '' ">
not equal to

i want to rid off the empty contain






Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL for-each/when problem Grofit XSLT 11 March 27th, 2008 10:26 AM
XSL problem cheez XSLT 1 September 14th, 2006 01:20 AM
Problem with XSL sandeepa XSLT 5 May 13th, 2005 04:31 AM
Help with xsl:when problem sundar_revathi XSLT 2 November 9th, 2004 07:39 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.