[Interest] xsl:variable & QXmlQuery
Sébastien Le Ray
sebastien-qt at orniz.org
Wed Dec 7 17:17:44 CET 2016
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20161207/0be0b739/attachment.html>
More information about the Interest
mailing list