How to update the variable value in xslt? How to update the variable value in xslt? xml xml

How to update the variable value in xslt?


If it happens that you need such a behavior in a transform, it means that probably you have to change the overall "design" of it. It's also hard to get what you are trying to do wihtout showing your input document and the wanted output.

Because you can't update variables, you have to rethink your code. The pattern (that I'm able to imagine) closest to your request is something like this:

    <xsl:template match="/">        <xsl:variable name="topLevelHeadings" select="//w:body/w:p                [w:pPr[w:pStyle[@w:val='Heading1']]]"/>        <xsl:variable name="beforeHeading">             <xsl:choose>                <xsl:when test="$topLevelHeadings">                    <xsl:value-of select="true()"/>                </xsl:when>                <xsl:otherwise>                    <xsl:value-of select="false()"/>                </xsl:otherwise>            </xsl:choose>        </xsl:variable>        <!-- your choose staff -->        <!-- for instance -->         <xsl:if test="$beforeHeading='true'">            <xsl:message>pass</xsl:message>        </xsl:if>    </xsl:template>


You can't. XSLT is a functional programming language so variables cannot be modified. Use recursion to do what you want instead.