xml - Surprising XSLT/XPath expression type behavior -


i ran behavior related types in xslt/xpath can't explain. here's snippet of xslt shows problem (it's not useful xslt, of course, represents pretty minimal demonstration question):

    <?xml version="1.0"?>     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">         <xsl:template match="/">             <xsl:variable name="root">                 <xsl:sequence select="root(.)"/>             </xsl:variable>             <xsl:if test="root(.)  $root">                 match             </xsl:if>         </xsl:template>     </xsl:stylesheet> 

you see "match" not displayed. however, if add as="node()" <xsl:variable name="root"> "match" is displayed.

can explain me understand why?

you can plug xslt http://xslttest.appspot.com explore problem. input xml work (e.g., <?xml version="1.0"?><foo/>).

thanks, josh.

to know difference between sequence , variable may go through following link.

to summarize, xsl:variable without as attribute creates new document(having own root node). using as attribute helps creating atomic value or sequence. here, variable wouldn't root node refer sequence(s) contains.

when use:

<xsl:variable name="root">             <xsl:sequence select="root(.)"/> </xsl:variable> 

with condition <xsl:if test="root(.) $root">, testing whether root of input xml document same root of variable root, false.

and when use:

<xsl:variable name="root" as="node()"> 

the condition, root(.) $root evaluates true both input document root , sequence generated variable root same.

and of course, mentioned michael.hor257k stylesheet shall versioned 2.0.

edit: declaring variable in following way make condition true()

<xsl:variable name="root" select="root(.)"/> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -