[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: combining two variables to generate XPATH
At 03:08 PM 12/17/2002, you wrote:
Is that FAQ outdated?? I know that the following code works just fine: You are being misled a bit by the syntax -- this can happen easily, given how concise and compact XPath is. But "a path with a single variable" is not resolved in the way you are thinking. Consider these two variable declarations: <xsl:variable name="nodeset1" select="//node"/> <xsl:variable name="nodeset2" select="'//node'"/> These variables both have values assigned by their declarations, but the resemblance stops there. The first variable is assigned a node set, consisting of all the elements called 'node' in the document. The second variable (despite its misleading name) is assigned a string value, "//node". In this situation, it's possible to say (in XPath/XSLT 1.0), for example, <xsl:for-each select="$nodeset1"> but not <xsl:for-each select="$nodeset2"/>. This is because in XSLT 1.0, it's not possible to iterate over and process a string, although you can do this with node sets. You can also say "$nodeset1/*" and get back the children of the nodes in variable nodeset1. But you can't say "*/$nodeset1" even though $nodeset1 is a node set. This is because since it's a node set already, you can't use it as a step in an XPath expression. Again despite appearances, "$nodeset1/*" is really an *operation* performed on $nodeset as an argument, not an XPath "Location Path" of the classic sort. A string doesn't magically turn into a set of nodes (for that, use an extension function to evaluate the string as XPath). Nor can you treat a nodeset as a string -- at least if the string you want is a string that would work as an XPath to select just that set of nodes. (If you treat a node set as a string, you get the string value of the first node in the set in document order.) I hope that helps. Once you understand how XPath works and what's a node and what's a string in the data model (and how you can assign either to variables and parameters), XSLT gets a lot easier. Cheers, Wendell Why can't I specify a second variable: ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ====================================================================== XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|