Andrew Truckle
Andrew Truckle

Reputation: 19157

Dynamically specifying a document into a variable using XSLT1

I have seen the answers here but they are not working.

I can use either of the following:

But I need to make this dynamic now. So I tried this but it doesn't like it:

<xsl:variable name="AssignHistory">
    <xsl:choose>
        <xsl:when test="//Settings/ForeignGroupMode=1">
            <xsl:value-of select="document('ForeignAssignHistory.xml')"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="document('AssignHistory.xml')"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>

It just won't work. It says:

Reference to variable or parameter 'AssignHistory' must evaluate to a node list.


To give this some context. This is what I have at the moment:

<td class="cellComments" colspan="4">
    <xsl:variable name="AssignHistory" select="document('AssignHistory.xml')"/>
    <xsl:variable name="week" select="Date/@NextWeek"/>
    <xsl:variable name="NextReviewQuestion" select="$AssignHistory/AssignmentHistory/*[name()=$week]/ReviewQuestion"/>
    <xsl:if test="normalize-space($NextReviewQuestion) != ''">
        <xsl:if test="normalize-space(ReviewQuestion) != ''">
            <span class="textReviewQuestionLabel">
                <xsl:value-of select="//Labels/NextReviewQuestion"/>&#160;
            </span>
            <span class="textReviewQuestion">
                <xsl:value-of select="$NextReviewQuestion"/>
            </span>
            <br />
        </xsl:if>
    </xsl:if>
    <br />
    <br />
    <br />
</td>

And I wanted to introduce that selection logic to choose the correct document.

Upvotes: 0

Views: 27

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117073

Perhaps try something like:

<xsl:variable name="AssignHistoryPath">
    <xsl:choose>
        <xsl:when test="//Settings/ForeignGroupMode=1">ForeignAssignHistory.xml</xsl:when>
        <xsl:otherwise>AssignHistory.xml</xsl:otherwise>
    </xsl:choose>
</xsl:variable>

<xsl:variable name="AssignHistory" select="document($AssignHistoryPath)"/>

Untested, because because no code to test with was provided.

Upvotes: 1

Related Questions