tags:

views:

72

answers:

2

I have some XSLT that looks like:

<xsl:choose>
    <xsl:when test="string(//User[@UserID = $UserID]/ROOT/Prop[@Nm = 'GreaseBoardCategory'])">
        <xsl:variable name="Type" select="concat('Documenter', //User[@UserID = $UserID]/ROOT/Prop[@Nm = 'GreaseBoardCategory'])"/>                         
    </xsl:when>
    <xsl:otherwise>
        <xsl:variable name="Type" select="concat('Documenter', user:GetUserType(string(//Payload/@SiteID), string(@UserID)))"/>                         
    </xsl:otherwise>
</xsl:choose>

And I want to assign a variable to it called "Type" I see from other examples that I should be doing this instead:

<xsl:variable name="Type">
    <xsl:choose>
        <xsl:when test="string(//User[@UserID = $UserID]/ROOT/Prop[@Nm = 'GreaseBoardCategory'])">
            <xsl:value-of select="concat('Documenter', //User[@UserID = $UserID]/ROOT/Prop[@Nm = 'GreaseBoardCategory'])"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="concat('Documenter', user:GetUserType(string(//Payload/@SiteID), string(@UserID)))"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>

But my variable is NOT getting set. It should hit the Otherwise block but never does. Any ideas? It doesn't get set to anything..

The only way to get Type to be set is to do away with the Choose/When/Otherwise statements and just pick one of the two options, like:

<xsl:variable name="Type" select="concat('Documenter', //User[@UserID = $UserID]/ROOT/Prop[@Nm = 'GreaseBoardCategory'])"/>

for example.

A: 

xsl:choose should work as expected. I would recommend that you simplify your example. Say

<xsl:value-of select="A"/>

in the when-branch and similar say "B" in ther otherwise-branch, instead of your more complex concatenations.

Finally, as others have asked, show us the code where you evaluate variable "Type" and the XML input. The mention of VBScript probably means that you are working with XSLT 1.0. I ask just to make sure.

xixxix
Once I create the Type variable, I put it into this:<xsl:value-of select="user:InsertPerson($SiteID, $VisitGUID, $ID, $FirstName, $MiddleName, $LastName, $Address1, $Address2, $City, $State, $Zipcode, $Degree, $SSN, $Phone1, $Phone2, $Priority, $LogonCategory, $HospitalID, $DocumentCreateTime, $CoSigner, $Type, $Primary, $AddTime)" disable-output-escaping="yes"/>However, when I set the Type variable using the choose/when/otherwise, I get an error. When I set the Type variable expliticly to either When or Otherwise's statement, it works correctly.
Shafique
and yes i'm working with XSLT 1.0..
Shafique
A: 

Okay I figured it out. The problem was in how I was accessing the XSLT variable Type.. I originally had:

<xsl:value-of select="user:InsertPerson($SiteID, $VisitGUID, $ID, $FirstName, $MiddleName, $LastName, $Address1, $Address2, $City, $State, $Zipcode, $Degree, $SSN, $Phone1, $Phone2, $Priority, $LogonCategory, $HospitalID, $DocumentCreateTime, $CoSigner, $Type, $Primary, $AddTime)" disable-output-escaping="yes"/>

But then I changed "..., $Type, ..." to "..., string($Type), ..." and that fixed it. I'm not sure why out of all the parameters, this is the only one that needed to be wrapped with "string(...)" but it did solve the problem.

Thanks for the help everyonE!

Shafique