How to update the variable value in xslt?

旧街凉风 提交于 2019-12-04 22:52:50

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!