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

Subject: RE: [xsl] Implementing a (fairly) complex business rule
From: "Bradley, Peter" <pbradley@xxxxxxxxxx>
Date: Tue, 30 Sep 2008 15:22:25 +0100
Thank you Michael.

Unfortunately, I can't use XSLT 2.0 as BizTalk doesn't understand it.

The background to this is that I'm getting some data from a database and
transforming it to an XML report format for the UK Higher Education
Statistics Agency (HESA).  The report has to be be valid and if we don't
submit it by the cut-off date, we are fined.

So no pressure there.

Most of the work is done in BizTalk, but BizTalk is not capable of
making this particular transformation without me writing custom XSLT.
However I have based it on the output from BizTalk to try to give myself
a start - being something of a newbie at this.  Once this transformation
is done, the file undergoes further processing in BizTalk for the
application of business rules not enshrined in the schema.

So much of what you see is actually the output from BizTalk and so I
wouldn't be at all surprised to hear that it's not ideal!

I know that this is pushing your goodwill a bit far, but would you mind
explaining when I do need text() and when I don't.  I've just tended to
leave it in if BizTalk's put it there and/or used it in the places where
BizTalk has used it elsewhere.  I'm beginning to see that this might
have been a bad decision.  So if I know where I do need it and where I
don't (in XSLT 1.0), I'll be able to get rid of it where it's not
necessary.

Many thanks for you patience

Peter


-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: 30 September 2008 14:57
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Implementing a (fairly) complex business rule

XSLT 2.0 is your friend. If you ran this in 2.0

string-length(s0:POSTCODE/text() = 0)

you would get an error message: the argument to string-length() must be
a
string, not a boolean. As it is, string-length("true") is 4,
string-length("false") is 5, and both 4 and 5 convert to the boolean
true
when treated as a boolean value.

Your closing paren is in the wrong place.

Incidentally, the "/text()" scattered throughout your code is
unnecessary
and in my view, bad practice. It means your code will fail if there are
comments in unexpected places in the source tree.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Bradley, Peter [mailto:pbradley@xxxxxxxxxx]
> Sent: 30 September 2008 14:07
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Implementing a (fairly) complex business rule
>
> I have a business rule that says that if the value of the
> REDUCEDI element is "00" and if the value of the DOMICILE
> element is in a list of values comprising XG, XH, XI, XK, XL,
> GG, JE and IM then a POSTCODE element must be present.  It
> should not be present otherwise.
>
> If the POSTCODE element is present and has a NULL value, then
> a ReasonForNull attribute should be included, with a value of "1".
>
> If the POSTCODE element is present and has a value, that
> value should be output and the ReasonForNull attribute should
> not be present.
>
> I have expressed this as follows:
>
> <!-- NULL is valid for a postcode -->
> <xsl:if
> test="/s0:HesaSqlExplicit_Response/s0:Institution/s0:Student/s
> 0:Instance
> /s0:REDUCEDI = '00'">
>   <xsl:if
>   test="s0:DOMICILE='XF' or s0:DOMICILE='XG' or s0:DOMICILE='XH' or
>   s0:DOMICILE='XI' or s0:DOMICILE='XK' or s0:DOMICILE='XL' or
>   s0:DOMICILE='GG' or s0:DOMICILE='JE' or s0:DOMICILE='IM'">
>     <POSTCODE>
>       <xsl:if test="string-length(s0:POSTCODE/text() = 0)">
>         <xsl:attribute name="ReasonForNull">
>           <xsl:text>1</xsl:text>
>         </xsl:attribute>
>       </xsl:if>
>       <xsl:if test="string-length(s0:POSTCODE/text()) > 0">
>         <xsl:value-of select="s0:POSTCODE/text()"/>
>       </xsl:if>
>     </POSTCODE>
>   </xsl:if>
> </xsl:if>
>
> However, in my output I am getting POSTCODE elements that
> both have a value and also have a ReasonForNull attribute
> with a value of "1".
>
> Can anyone put me out of my misery?  I just cannot see how
> this can happen.
>
> Thanks
>
>
> Peter

Current Thread