[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: create xml from incoming xml and load it into a v

Subject: Re: create xml from incoming xml and load it into a variable
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 25 Jul 2008 17:00:34 -0400
Re:  create xml from incoming xml and load it into a  v
Sudeshna,

At 04:37 PM 7/25/2008, you wrote:
...
Inside the loop, I need to use <xsl:key name="ccc" match="subroot" use="ccc"/>.
But while transforming, I am receiving the following error:


xsl:key is not allowed in this position in the stylesheet!

How do I use "key" tag inside a variable which contains xml?

Keys are declared at the top level, not inside templates or variable declarations. Once a key is declared at the top level (with the xsl:key element), it can be used anywhere an XPath expression is allowed (with the key() function), including inside a variable declaration.


This does not mean, however, that you can't do what you need to do. You just can't do it in the way you are thinking. You say "Inside the loop, I need to use xsl:key..." but this isn't right. Or actually, in the absence of more information, it's meaningless. It's like saying "I need to use a toothbrush" without telling us why. Maybe you think you need to use a toothbrush, but a hair brush is what you really need.

If you explain what you are trying to achieve, preferably with a reduced sample of your input and your desired output, we can explain more. If a solution exists at all (and it undoubtedly does), it will necessarily be one that does not require an illegal construction.

<!--Traverse the variable-->
  <xsl:for-each select="xalan:nodeset($var)/root/subroot">
    <xsl:key name="ccc" match="subroot" use="11"/> ===> ERROR!!!!
  </xsl:for-each>
</xsl:template>

In this case, it appears your concern is declaring a key that will be available for use inside the traversal of your $var variable as a node set. If so, don't worry about it. Declare the key at the top level and use it normally inside the template. The rule (in XSLT 1.0) is that a key retrieves nodes from the document containing the context node. So when your context is inside $var, the key will retrieve nodes from inside $var. (The declaration only says what to retrieve, it does not define a scope for the retrieval.)


If you need to retrieve nodes from another document (maybe your original source document) when inside $var, this can be done too, generally by switching the context back to the other source (in XSLT 1.0, with another xsl:apply-templates or xsl:for-each). But I don't know if this is the case here.

Cheers,
Wendell



======================================================================
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
======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.