Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > How to deal with scoped XML Schema keys in XSLT

Reply
Thread Tools

How to deal with scoped XML Schema keys in XSLT

 
 
David Blickstein
Guest
Posts: n/a
 
      07-18-2005
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


 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      07-18-2005

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
 
Reply With Quote
 
 
 
 
David Blickstein
Guest
Posts: n/a
 
      07-18-2005
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" <> wrote in message
news:...
>
> 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



 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      07-18-2005


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/
 
Reply With Quote
 
David Carlisle
Guest
Posts: n/a
 
      07-18-2005

> 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
 
Reply With Quote
 
David Blickstein
Guest
Posts: n/a
 
      07-18-2005
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" <> wrote in message
news:...
>
> > 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



 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      07-18-2005


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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
XML Schema to XML Schema Conversion Hari Om XML 1 03-02-2004 09:04 PM
XML schema regular expressions question and recommended XML Schema book Fred Smith XML 1 02-05-2004 11:12 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57