0
votes

I am using XSLT 2.0 and have a variable who contains dates separated by comma. I try to tokenize this variable in a for-each but in execution, I have the error: "Cannot select a node here: the context item is an atomic value"

Here is my code:

<xsl:variable name="datesMois">
    <xsl:call-template name="dayOfMonth">
        <xsl:with-param name="pDay" select="01" />
        <xsl:with-param name="pMonth" select="/workfile/query/@month" />
        <xsl:with-param name="pYear" select="/workfile/query/@year" />          
    </xsl:call-template>
</xsl:variable>
<xsl:variable name="currentstartdate" select="substring-before(., 'T')" />
<xsl:for-each select="tokenize($datesMois,',')">
    <xsl:variable name="dateJour" select="." />
...

The template dayOfMonth returns the days for the month given in parameters. I don't understand what is wrong in my code, could you please help me?

Thanks.

1
Please add more context to your question as well. That is, especially the code for the named template "dayOfMonth" - if not the entire stylesheet. Also, a sample XML input would help. - Mathias Müller

1 Answers

0
votes

Assuming you have something like

<xsl:variable name="datesMois">
    <xsl:call-template name="dayOfMonth">
        <xsl:with-param name="pDay" select="01" />
        <xsl:with-param name="pMonth" select="/workfile/query/@month" />
        <xsl:with-param name="pYear" select="/workfile/query/@year" />          
    </xsl:call-template>
</xsl:variable>
<xsl:variable name="currentstartdate" select="substring-before(., 'T')" />
<xsl:for-each select="tokenize($datesMois,',')">
    <xsl:variable name="dateJour" select="." />
    <xsl:value-of select="foo[date = $dateJour]"/>

you would get the error you describe, to avoid that you would need to store the context node outside of the for-each in a variable as in

<xsl:variable name="datesMois">
    <xsl:call-template name="dayOfMonth">
        <xsl:with-param name="pDay" select="01" />
        <xsl:with-param name="pMonth" select="/workfile/query/@month" />
        <xsl:with-param name="pYear" select="/workfile/query/@year" />          
    </xsl:call-template>
</xsl:variable>
<xsl:variable name="currentstartdate" select="substring-before(., 'T')" />

<xsl:variable name="context" select="."/>

<xsl:for-each select="tokenize($datesMois,',')">
    <xsl:variable name="dateJour" select="." />
    <xsl:value-of select="$context/foo[date = $dateJour]"/>

I had to guess how your code might look that causes the error, if you still have problems then post the exact line of your code that causes the error.