How to deal with scoped XML Schema keys in XSLT

Discussion in 'XML' started by David Blickstein, Jul 18, 2005.

  1. 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
     
    David Blickstein, Jul 18, 2005
    #1
    1. Advertising

  2. 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
     
    David Carlisle, Jul 18, 2005
    #2
    1. Advertising

  3. 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
     
    David Blickstein, Jul 18, 2005
    #3
  4. 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/
     
    Martin Honnen, Jul 18, 2005
    #4

  5. > 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
     
    David Carlisle, Jul 18, 2005
    #5
  6. 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
     
    David Blickstein, Jul 18, 2005
    #6
  7. 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/
     
    Martin Honnen, Jul 18, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    738
    Stylus Studio
    Aug 3, 2004
  2. Markus
    Replies:
    1
    Views:
    1,640
    Markus
    Nov 23, 2005
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,314
    Stanimir Stamenkov
    Apr 25, 2005
  4. rbt

    deal or no deal

    rbt, Dec 22, 2005, in forum: Python
    Replies:
    7
    Views:
    587
    Duncan Smith
    Dec 28, 2005
  5. Replies:
    3
    Views:
    3,080
Loading...

Share This Page