Comparing negative number with xsl choose - xslt

i am trying to do equal comparison of negative number, but i dont see any output. below is the code.
<xsl:variable name="OwnershipStatus" select="Veh_Ownsp[Veh_Ownsp_ID=$OwnerData1/Veh_Ownsp_ID]/Ownsp_Cntl_Type_ID"/>
Here OwnershipStatus is returninenter code hereg -1
xsl:choose>
<xsl:when test="$OwnershipStatus = -1" >
<xsl:value-of select="Or"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="And"/>
</xsl:otherwise>
</xsl:choose>

I guess you are trying to hardcode 'Or' and 'And' in case of condition getting evaluated to true and false, respectively. Since the values are literal they should be enclosed with single quotes as shown below:
<xsl:choose>
<xsl:when test="$OwnershipStatus = -1" >
<xsl:value-of select="'Or'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'And'"/>
</xsl:otherwise>

Related

xsl:choose - Hardcoded 0's being added to end of XSLT string

I am having an issue that I cannot figure out in XLST where there are hardcoded 0's being added to the end of a string that I am not calling for. I am using a choose element to prompt placement of the string or to otherwise pick three 0's.
Can anyone tell in my code what I am doing wrong? See below:
<xsl:for-each select="Export/Record">
<xsl:if test="DebitAmount!=0 and DebitAmount!=''">
<xsl:value-of select="ChargedCorpLedgerCode" /><xsl:text>,</xsl:text>
<xsl:value-of select="DepartmentLedgerCode" /><xsl:text>,</xsl:text>
<xsl:value-of select="CategoryJournalNumber" /><xsl:text>,</xsl:text>
<xsl:value-of select="PFAM" /><xsl:text> 0000,</xsl:text>
<xsl:value-of select="LOC" /><xsl:text> 0000,</xsl:text>
<xsl:value-of select="ACTV" /><xsl:text> 0000,</xsl:text>
<xsl:value-of select="CLIENT"/><xsl:text> 0000000,</xsl:text>
<xsl:choose>
<xsl:when test="ProjectLedgerCode=null">
<xsl:value-of select="ProjectLedgerCode" /><xsl:text>,</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ProjectLedgerCode" /><xsl:text> 000,</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="DebitAmount" /><xsl:text>,</xsl:text>
<xsl:value-of select="''" /><xsl:text>,</xsl:text>
<xsl:value-of select="CategoryDesc" /><xsl:text>,</xsl:text>
<xsl:text>
</xsl:text>
</xsl:if>
my outcome looks like the below where the 000's are adding correctly when the column is blank, but when it is not, it adds the ProjectLedgerCode + 000
This test:
<xsl:when test="ProjectLedgerCode=null">
will return true if the string-value of ProjectLedgerCode is equal to the string-value of a sibling element named null.
If you want to test for ProjectLedgerCode not having a string-value, use:
<xsl:when test="ProjectLedgerCode=''">
or:
<xsl:when test="not(string(ProjectLedgerCode))">
In addition, I believe your results are mixed up.

XSL How to find the greater of 2 strings?

Have the below newbie question on how to compare and find the greater of 2 strings please -
<xsl:variable name="String1" select="ABC"/>
<xsl:variable name="String2" select="DEF"/>
My focus of comparison between the 2 strings is based on the first letter being greater than the other, so, i did this -
<xsl:variable name="String1First" select="substring($String1,1,1)"/>
<xsl:variable name="String2First" select="substring($String2,1,1)"/>
so i have the values of the first letters in string1First & String2First for the compare.
Now the actual comparison is the issue - just tried to check if string1 > string2 but that didnt give me the right result obviously.
<xsl:variable name="Output">
<xsl:choose>
<xsl:when test="'$String1First' > '$String2First'">
<xsl:text> First string is greater </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> Second string is greater </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
tried using compare function, but that didn't seem to work.
<xsl:variable name="Output">
<xsl:choose>
<xsl:when test="(compare('$String1First', '$String2First')) = 1">
<xsl:text> First string is greater </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> Second string is greater </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
also tried:
<xsl:variable name="Alphabet" select="ABCDEFGHIJKLMNOPQRSTUVWXYZ"/>
<xsl:number name="PosNo" select="index-of-string($Alphabet,$String1First)">
<xsl:number name="PosNo2" select="index-of-string($Alphabet,$String2First)">
to compare as numbers by taking the position, but got the whole format wrong.
Could you please help with the easiest way to achieve this please?
Many thanks for your kind assistance.

XSLT - Format-number output NaN

I'm new to XSLT. I'm working with zip codes and I'm trying to padleft zeros to any zipcode under 5 characters. Otherwise, I want my code to simply write the input parameter exactly as is. I'm running into a problem when the zipcode starts with or contains a letter. My output is returning a NaN. How do I tell the code that whenever the zipcode contains a letter, to simply write out the zipcode as is without running the "format-number" logic? I know about the "starts-with" and "contain" functions but I don't totally understand how they work.
<xsl:template name="MyZipCodeUnder5DigitsPadLeftZerosTemplate">
<xsl:param name="BillToZipcode" />
<xsl:choose>
<xsl:when test="string-length($BillToZipcode) < 5">
<xsl:element name="PostalCode">
<xsl:value-of select="format-number($BillToZipcode, '00000')" />
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="PostalCode">
<xsl:value-of select="$BillToZipcode"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
How about:
<xsl:template name="MyZipCodeUnder5DigitsPadLeftZerosTemplate">
<xsl:param name="BillToZipcode" />
<PostalCode>
<xsl:choose>
<xsl:when test="number($BillToZipcode)">
<xsl:value-of select="format-number($BillToZipcode, '00000')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$BillToZipcode"/>
</xsl:otherwise>
</xsl:choose>
</PostalCode>
</xsl:template>
This assumes no (numerical) Zipcode can have more than 5 digits. If this is not true, you could use:
<xsl:when test="number($BillToZipcode) < 10000">

XSL condition statement

i have a problem with this statement :
<xsl:choose>
<xsl:when test="cars[#id='1']">
<xsl:choose>
<xsl:when test="cars[#id='1']='1'">true</xsl:when>
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
true
</xsl:otherwise>
</xsl:choose>
"True" is allways displayed even if my "cars[#id='1'])='0' (Not exists).
Thanks for Help
Could it be that your input isn't matching at all?
<xsl:choose>
<xsl:when test="cars[#id='1']">
<xsl:choose>
<xsl:when test="cars[#id='1']='1'">true</xsl:when>
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
true <!-- change this and see what it returns -->
</xsl:otherwise>
</xsl:choose>
From the information given, there could be any number of reasons. Common beginner's mistakes would suggest the following possibilities:
(a) the 'cars' element is actually in a namespace
(b) your context node for executing this code is not the parent of the 'cars' element

XSL variable assignment

I have another simple xsl variable question. I'm trying to evaluate an expression and toggle an 'AM' or 'PM' suffix. The variable never evaluates to anything. I've even changed my test to with no luck.
<xsl:variable name="DisplayAMPM">
<xsl:choose>
<xsl:when test="number(substring($LastBootUpTime, 9,2))>11">
<xsl:value-of select="PM"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="AM"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:copy-of select="DisplayAMPM"/>
If you use value-of, put the "AM" and "PM" in quotes so that the processor sees it as a string.
Also, if you reference the variable, like you're trying to do in the copy-of, don't forget the $.
<xsl:variable name="DisplayAMPM">
<xsl:choose>
<xsl:when test="number(substring($LastBootUpTime, 9,2))>11">
<xsl:value-of select="'PM'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'AM'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:copy-of select="$DisplayAMPM"/>
You have a runaway > character in your test attribute which should of course be >.
Secondly, you don't copy your variable ($DisplayAMPM), instead you copy the (nonexistent?) DisplayAMPM element child node set.