Problem with xsl:sequence and xsl:variable
Added by Anonymous over 15 years ago
Legacy ID: #7399877 Legacy Poster: Lea Hayes (numberkruncher)
Hi, I am using xsl:sequence to return a value from a function. This value gets put into a variable. I have noticed that the content inside the variable is acting as a new temporary document because calling "generate-id" on the element in the variable differs from the source document. Here is a test which I put together: <xsl:variable name="a1" select="saxon:evaluate(concat('doc(''',$href-path,''')//intro'))"/> <xsl:variable name="b1" select="saxon:evaluate(concat('doc(''',$href-path,''')//intro'))"/> <xsl:variable name="c1" select="doc($href-path)//intro"/> <xsl:variable name="d1" select="doc($href-path)//intro"/> <xsl:variable name="a2"> <xsl:sequence select="saxon:evaluate(concat('doc(''',$href-path,''')//intro'))"/> </xsl:variable> <xsl:variable name="b2"> <xsl:sequence select="saxon:evaluate(concat('doc(''',$href-path,''')//intro'))"/> </xsl:variable> <xsl:variable name="c2"> <xsl:sequence select="doc($href-path)//intro"/> </xsl:variable> <xsl:variable name="d2"> <xsl:sequence select="doc($href-path)//intro"/> </xsl:variable> a1: <xsl:value-of select="generate-id($a1)"/><br/> b1: <xsl:value-of select="generate-id($b1)"/><br/> c1: <xsl:value-of select="generate-id($c1)"/><br/> d1: <xsl:value-of select="generate-id($d1)"/><br/> a2: <xsl:value-of select="generate-id($a2)"/><br/> b2: <xsl:value-of select="generate-id($b2)"/><br/> c2: <xsl:value-of select="generate-id($c2)"/><br/> d2: <xsl:value-of select="generate-id($d2)"/> The output of this test is: a1: d5e53 b1: d5e53 c1: d5e53 d1: d5e53 a2: d16 b2: d17 c2: d18 d2: d19 I have two concerns with this problem: - Generated identifiers do not match, a pretty serious bug in my output. - Excessive duplication of content. Why are the variables which use xsl:sequence different? Is there a way in which I can work around this problem? I was under the impression that xsl:sequence returned the original nodes unless combined with other content, in which case it is the same as xsl:copy-of. Many thanks, Lea Hayes
Replies (2)
RE: Problem with xsl:sequence and xsl:variable - Added by Anonymous over 15 years ago
Legacy ID: #7400407 Legacy Poster: Michael Kay (mhkay)
General XSLT coding questions (as distinct from Saxon product-specific questions) are best asked on the xsl-list at mulberrytech.com. An xsl:variable with no select or as attribute always creates a new temporary document. If you just want to select an existing node, then instead of this: <xsl:variable name="a2"> <xsl:sequence select="EXPR"/> </xsl:variable> do this: <xsl:variable name="a2" select="EXPR"/> You could also solve the problem by adding as="node()*" to the xsl:variable.
RE: Problem with xsl:sequence and xsl:variabl - Added by Anonymous over 15 years ago
Legacy ID: #7401115 Legacy Poster: Lea Hayes (numberkruncher)
That has solved my problem. Thanks Michael!
Please register to reply