Re: [xsl] Implementing a (fairly) complex business rule

Subject: Re: [xsl] Implementing a (fairly) complex business rule
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 30 Sep 2008 15:24:47 +0100
> Presumably the test for an empty node in the other xsl:if statement
> should be:
> 
> <xsl:if test="not(s0:POSTCODE/text())"> ...

yes, depending on what you mean by empty, for example if you want
<POSTCODE>
</POSTCODE>
to be "empty" even though it has a newline, then you need to eirther
strip white space nodes (xsl:strip-space) or do something like
 <xsl:if test="normalize-space(s0:POSTCODE)"> ...

But

<xsl:if test="s0:POSTCODE/text()">
  <xsl:value-of select="s0:POSTCODE/text()"/>
</xsl:if>

could be written as


  <xsl:value-of select="s0:POSTCODE"/>

No need for a test, if there is nothing there nothing will get copied.

assuming that this now works, then presumably the input structure is
right for this.



personally I'd write

  <DOMICILE>
      <xsl:attribute name="codeListAgencyName">
        <xsl:text>HESA</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="codeListName">
        <xsl:text>DOMICILE</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="languageID">
        <xsl:text>en</xsl:text>
      </xsl:attribute>
      <xsl:value-of select="s0:DOMICILE/text()"/>

as

  <DOMICILEcodeListAgencyName="HESA" codeListName="DOMICILE" languageID="en">
      <xsl:value-of select="s0:DOMICILE"/>

because my typing (as some people on this list have cruelly commented
in the past) isn't that accurate, so short is good, increases the chance
of avoiding typos...

the last line (without text()) is actually different in behaviour, if
you have
<DOMICILE>some <!-- I edited this-->text</DOMICILE>

then (in XSLT 1) 
      <xsl:value-of select="s0:DOMICILE/text()"/>
is "some " as that's the first text node, but
      <xsl:value-of select="s0:DOMICILE"/>
is "some text" as that is the string value of the element, which
normally is what you want, to ignore comments.

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

Current Thread