![]() |
How to deal with scoped XML Schema keys in XSLT
I'm dealing with an XML Schema that uses Schema keys. Specifically the
Schema takes advantage of the ability to define the keys to be specific to a particular scope, which allows duplication between scopes. That is I can have a schema like this: <Company Name="Nike"> <Product Name="Sneaker"/> <Warehouse ProductStored="Sneaker"/> </Company> <Company Name="Asics"> <Product Name="Sneaker"/> <Warehouse ProductStored="Sneaker"/> </Company> The key is the "Name" attribute of the "Product" tag and its scope is limited to the local "Company". And ProductStored is the keyref to that key. If the key were not scoped, "Sneaker" would be a duplicate but because it's scoped to the company, each reference isunambiguous. Now the question I have is... in XSLT, I want to use these scoped keys because I want to create hyperlinks from the Warehouse output to the Product. Is there any support in XSLT to handle locally scoped keys? If not, are there techniques to deal with this? Thanks, Dave Blickstein |
Re: How to deal with scoped XML Schema keys in XSLT
XSLT2 adds explict support (in a new 3rd argument to key()) to specifying the scope in xslt1 you'd normally do something like <xsl:key name="n" match="Product" use="concat(../@Name,':',@Name)"/> <xsl:template match="Warehouse"> .....select="key('n',"concat(../@Name,':',@Name)" ... (If by "support" you meant automatically getting information from the schema defined key, then xslt doesn't do this, even in the otherwise schema-aware xslt2 draft.) David |
Re: How to deal with scoped XML Schema keys in XSLT
That's exactly the information I was looking for.
I had figured I could do something like what you suggest for XSLT 1.0 but obviously the new V2 extension to key() is way better. I wasn't figuring on seeing XSLT-awareness of Schema anytime soon. Thanks David, db "David Carlisle" <davidc@nag.co.uk> wrote in message news:yg44qasma61.fsf@penguin.nag.co.uk... > > XSLT2 adds explict support (in a new 3rd argument to key()) to > specifying the scope > > in xslt1 you'd normally do something like > > <xsl:key name="n" match="Product" use="concat(../@Name,':',@Name)"/> > > <xsl:template match="Warehouse"> > ....select="key('n',"concat(../@Name,':',@Name)" ... > > (If by "support" you meant automatically getting information from the > schema defined key, then xslt doesn't do this, even in the otherwise > schema-aware xslt2 draft.) > > David |
Re: How to deal with scoped XML Schema keys in XSLT
David Blickstein wrote: > I'm dealing with an XML Schema that uses Schema keys. Specifically the > Schema takes advantage of the ability to define the keys to be specific to a > particular scope, which allows duplication between scopes. > > That is I can have a schema like this: > > <Company Name="Nike"> > <Product Name="Sneaker"/> > <Warehouse ProductStored="Sneaker"/> > </Company> > <Company Name="Asics"> > <Product Name="Sneaker"/> > <Warehouse ProductStored="Sneaker"/> > </Company> > > The key is the "Name" attribute of the "Product" tag and its scope is > limited to the local "Company". And ProductStored is the keyref to that > key. If the key were not scoped, "Sneaker" would be a duplicate but > because it's scoped to the company, each reference isunambiguous. > > Now the question I have is... in XSLT, I want to use these scoped keys > because I want to create hyperlinks from the Warehouse output to the > Product. XPath 1.0 and XSLT 1.0 do not have any W3C XML schema support, they predate the XML schema specification by two years I think. So there is nothing specific to dealing with such keys defined in a schema. But of course XPath allows you to write expressions relative to a certain node and that way if you process a <Company> element node you can certainly look for Product[@Name = following-sibling::Warehouse/@ProductStored] And of course XSLT 1.0 has the <xsl:key> element to set up your own keys for XSLT processing and then use the XSLT key function to lookup stuff. -- Martin Honnen http://JavaScript.FAQTs.com/ |
Re: How to deal with scoped XML Schema keys in XSLT
> I wasn't figuring on seeing XSLT-awareness of Schema anytime soon. XSLT2 will (have the option of) seeing all global and local element declarations, and type declarations from a schema. It just doesn't see key constraints from a schema. The schema awareness is an optional feature of xslt2 (which means, today, that you get it if you use the paid-for version of saxon, and don't get it if you use the free one) David |
Re: How to deal with scoped XML Schema keys in XSLT
Is there a freely distributed version of XSLT that supports the XSLT V2
updated version of the key() function (the one with the 3rd argument)? At the moment, I'm using whatever it is that comes with XMLSpy and Xalan on HP-UX. I think XMLSpy supports XSLT V2, I'm not sure about Xalan. I don't think I have any need for Schema awareness. Only the ability to use the key function to limit the scope of a key. db "David Carlisle" <davidc@nag.co.uk> wrote in message news:yg41x5wm8oq.fsf@penguin.nag.co.uk... > > > I wasn't figuring on seeing XSLT-awareness of Schema anytime soon. > > > XSLT2 will (have the option of) seeing all global and local element > declarations, and type declarations from a schema. It just doesn't see > key constraints from a schema. The schema awareness is an optional > feature of xslt2 (which means, today, that you get it if you use the > paid-for version of saxon, and don't get it if you use the free one) > > David |
Re: How to deal with scoped XML Schema keys in XSLT
David Blickstein wrote: > Is there a freely distributed version of XSLT that supports the XSLT V2 > updated version of the key() function (the one with the 3rd argument)? According to the documentation <http://www.saxonica.com/documentation/functions/intro/xslt_key.html> Saxon does that since 8.1 so you could get the latest Saxon 8 version from <http://saxon.sourceforge.net/> -- Martin Honnen http://JavaScript.FAQTs.com/ |
| All times are GMT. The time now is 07:35 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.