You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Alex Reuter <ar...@monsterdaata.com> on 2001/02/22 15:56:33 UTC

test for null

Hello,

Is there any way to test for null with xsl?  I need to not display something
if one or more fields is null, like so <SomeField/>.

Thanks,
Alex





Xalan-java and Performance of XSLT

Posted by Garrett Serack <ma...@experientia.org>.
I'm building a rather large application which uses quite a lot of xslt for document generation, and the performance is not what I'd call good.  I'm seeing transformations take about 30 or so seconds on a PIII/850/512MB ram.  The java VM, is not using more than 30 or so megs of ram, but my documents are quite,um,complex.

As it is, the XSLT code is quite complex too.  Is there any way of profiling XSLT? find out which peices are my sore spots?

I am caching the templates, and the documents to be transformed, but if anyone has any ideas about how to improve my performance, I'd be grateful...


Garrett Serack

RE: test for null

Posted by Alex Reuter <ar...@monsterdaata.com>.
Why hell....it works! thanks
  -----Original Message-----
  From: Frank Griffin [mailto:ftg@ntplx.net]
  Sent: Thursday, February 22, 2001 10:35 AM
  To: xalan-dev@xml.apache.org
  Subject: Re: test for null


  Alex Reuter wrote:
    Is there any way to test for null with xsl?  I need to not display
something
    if one or more fields is null, like so <SomeField/>.
  Given
  <SomeGroup>
    <SomeField>non-null field</SomeField>
    <SomeField/>
    ...
  </SomeGroup>

  you could do

  <xsl:for-each select="SomeField">
    <xsl:variable name="fieldValue">
      <xsl:value-of select="."/>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$fieldValue">
        <TAG>Value of field is
          <xsl:value-of select="$fieldValue"/>
        </TAG>
      </xsl:when>
      <xsl:otherwise>
        <TAG>Field is null</TAG>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>

  The test will evaluate a non-null string as TRUE.  There's probably a way
to do this without the variable, but this popped into my head first.


Re: test for null

Posted by Frank Griffin <ft...@ntplx.net>.
Alex Reuter wrote:

> Is there any way to test for null with xsl?  I need to not display something
> if one or more fields is null, like so <SomeField/>.

Given

<SomeGroup>
  <SomeField>non-null field</SomeField>
  <SomeField/>
  ...
</SomeGroup>

you could do

<xsl:for-each select="SomeField">
  <xsl:variable name="fieldValue">
    <xsl:value-of select="."/>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="$fieldValue">
      <TAG>Value of field is
        <xsl:value-of select="$fieldValue"/>
      </TAG>
    </xsl:when>
    <xsl:otherwise>
      <TAG>Field is null</TAG>
    </xsl:otherwise>
  </xsl:choose>
</xsl:for-each>

The test will evaluate a non-null string as TRUE.  There's probably a way to do this without the variable, but this popped into my head first.