Boolean true and false as strings

H

Hoi Wong

As I'm trying to do conditional variable assignment (see the post below), I
have to use

<xsl:variable name="someName">
<xsl:value-of select="true()"/>
</xsl:variable>

instead of

<xsl:variable name="someName" select="true()"/>

but apparently value-of select converts my variable to string instead of
boolean, and that leaves a dangerous trap in my code that
 
H

Hoi Wong

I accidentially hit send before finishing...

=============================

As I'm trying to do conditional variable assignment (see the post below), I
have to use

<xsl:variable name="someName">
<xsl:value-of select="true()"/>
</xsl:variable>

instead of

<xsl:variable name="someName" select="true()"/>

but apparently value-of select converts my variable to string instead of
boolean, and that leaves a dangerous trap in my code that people who follow
up might try to test the string and always return TRUE.

Is there any other ways to assign boolean values using <xsl:variable>
without putting "select" at the same line.

Thanks.

Cheers,
Hoi
 
D

David Carlisle

Hoi said:
I accidentially hit send before finishing...

=============================

As I'm trying to do conditional variable assignment (see the post below), I
have to use

<xsl:variable name="someName">
<xsl:value-of select="true()"/>
</xsl:variable>

instead of

<xsl:variable name="someName" select="true()"/>

but apparently value-of select converts my variable to string instead of
boolean, and that leaves a dangerous trap in my code that people who follow
up might try to test the string and always return TRUE.

Is there any other ways to assign boolean values using <xsl:variable>
without putting "select" at the same line.

Thanks.

Cheers,
Hoi

you coul duse copy-of instead of value-of which avoids value-of making a
text node, but in xslt1, it won't help as if you use xsl:variable
without a select attribute the result is a result tree fragment, which
isn't what you want.


If you are using xslt2 you can use if()... then... else ... within the
select expression.

If you are using xslt1 and have access to a x:noe-set() extesnion
function (almost all xslt 1 engines support this) then normally the
thing to do is not define 40 global variables but rather just define one
structured variable.

so don't use $a1, ..... $a40, use
$a/a1, ...$a/a40

where the global variable $a holds an in-memory XML fragment that you
construct that contains all the data.

David
 
H

Hoi Wong

I'm using the XSLT scripts in MATLAB. That mean Saxon on XSLT 1.0.

I guess what you said about the nodeset extension means I should made my
code something like this:

<xsl:variable name="DEVICE_TYPE_FLAGS">
<xsl:choose>
<xsl:when test="$APP_MODEL = 2812">
<IS_ICD>true</IS_ICD>
<IS_ATRIAL_ICD>true</IS_ATRIAL_ICD>
</xsl:when>
<xsl:eek:therwise>
<IS_ICD>true</IS_ICD>
<IS_ATRIAL_ICD>false</IS_ATRIAL_ICD>
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>

But I'm still stuck with strings in the text node of tags like <IS_ICD>. Is
there a way that I can make the contents inside a tag boolean?

Thanks.

Cheers,
Hoi
 
D

David Carlisle

Hoi said:
> But I'm still stuck with strings in the text node of tags like <IS_ICD>.


XML is a textual document format, if you encode things in XML, that's
the price you pay.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top