Nevermind, this seems to be tied to strange scoping rules (variables are "leaking" outside their scope refusing to get their value changed). Using named templates + params did the trick

Le 07/12/2016 à 17:17, Sébastien Le Ray a écrit :

Hi list,

I've a strange behavior with xsl:variables and nested scopes.

First, something like :

<xsl:template match="//whatever"> <whatever>
<xsl:apply-templatesselect="@*"/>
<xsl:for-eachselect="something">
<xsl:variablename="localId"select="@local-id"/>
<xsl:variablename="otherId"select="@other-id"/>
<xsl:iftest="not(boolean(//no/matter/what/*[@attr=$localId]))">
<dont-care/>
</xsl:if>
</xsl:for-each>
</whatever>
</xsl:template>

Does not work under Qt (xsltproc is fine), tracking down the issue it appears that $localId is not set when the XPath get evaluated, not a big deal, I thought, I simply did something like

<xsl:template match="//whatever"> <whatever>
<xsl:apply-templatesselect="@*"/>
<xsl:for-eachselect="something">
<xsl:variablename="localId"select="@local-id"/>
<xsl:variablename="otherId"select="@other-id"/>
<xsl:iftest="not(boolean(//no/matter/what/*))"> <xsl:if test="@attr=$localId">
<dont-care/> </xsl:if>
</xsl:if>
</xsl:for-each>
</whatever>
</xsl:template>

That doesn't work neither.

Only way to make it work I found until now is to somehow output the variable before using it eg

<xsl:template match="//whatever"> <whatever>
<xsl:apply-templatesselect="@*"/>
<xsl:for-eachselect="something">
<xsl:variablename="localId"select="@local-id"/>
<xsl:variablename="otherId"select="@other-id"/> <xsl:value-of select="$localId"/>
<xsl:iftest="not(boolean(//no/matter/what/*[@attr=$localId]))">
<dont-care/>
</xsl:if>
</xsl:for-each>
</whatever>
</xsl:template>

This works but pollutes the XML

Is this a known limitation or am I missing something?

Is there a way to achieve the same effect without outputing the variable?

Regards





_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to