This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Null Values


Lawrence Pravin wrote:
> My requirement is to remove tag names when I convert from one xml to another 
> xml, if there is no data.
> e.g
> <F1>1234</F1>
> <F2>1234</F2>
> <F3></F3>
> <F4>1234</F4>
> 
> to
> 
> <F1>1234</F1>
> <F2>1234</F2>
> <F4>1234</F4>
> 
> Is there any general method to do this, instead of checking node by node.

You could avoid selecting the nodes for processing in the first place.
For example,

<xsl:template match="foo">
  <xsl:apply-templates select="*[normalize-space()]"/>
</xsl:template>

would select only the element children of the current 'foo' element
if they have non-empty string-values, after normalization of whitespace.

Alternatively, process all the elements, but use different templates for
the empty and non-empty ones:

<xsl:template match="*[normalize-space()]">
  <xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="*[not(normalize-space())]"/> <!-- does nothing -->

   - Mike
_____________________________________________________________________________
mike j. brown, software engineer at  |  xml/xslt: http://skew.org/xml/
webb.net in denver, colorado, USA    |  personal: http://hyperreal.org/~mike/

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]