XSLT 2.0 space separated list type access with Saxon 9.1 -sa -val

Discussion in 'XML' started by RolfK, Feb 6, 2009.

  1. RolfK

    RolfK Guest

    Dear ALL

    I have defined a list type in a schema and validation works well !

    However, I could not succeed to get a single item out of the space
    separted list.
    I'm using the schema aware version of SAXON 9.1

    My element in questions looks like this:
    <Agenda CSSColorNames="red green"/>

    My schema part (snipet) for the attribute is this:
    <xsi:simpleType name="tCSSColorNames">
    <xsi:list>
    <xsi:simpleType>
    <xsi:restriction base="xsi:string">

    <xsi:enumeration value="aqua"/>
    ...... <xsi:enumeration
    value="teal"/>

    </xsi:restriction>
    </xsi:simpleType>
    </xsi:list>
    </xsi:simpleType>

    Acessing the attribute and using tokenize() leads to an error.
    How to access the nth element defined in the attribute
    CSSColorNames ??

    Basically I imagine to do something like this to do this:
    <xsl:variable select="Agenda/@CSSColorNames[position()=2]"/>

    Thanks a lot

    Rolf
    RolfK, Feb 6, 2009
    #1
    1. Advertising

  2. RolfK

    Mukul Gandhi Guest

    On Feb 6, 4:45 pm, RolfK <> wrote:
    > My element in questions looks like this:
    > <Agenda CSSColorNames="red  green"/>


    > Acessing the attribute and using tokenize() leads to an error.
    > How to access the nth element defined in the attribute
    > CSSColorNames ??


    I think, accessing the attribute and doing tokenize() is the right
    way. What error message are you getting?

    >
    > Basically I imagine to do something like this to do this:
    > <xsl:variable select="Agenda/@CSSColorNames[position()=2]"/>


    I think, this is not the correct way to do this.
    Mukul Gandhi, Feb 6, 2009
    #2
    1. Advertising

  3. RolfK

    RolfK Guest

    On 6 Feb., 12:59, Mukul Gandhi <> wrote:
    > On Feb 6, 4:45 pm, RolfK <> wrote:
    >
    > > My element in questions looks like this:
    > > <Agenda CSSColorNames="red  green"/>
    > > Acessing the attribute and using tokenize() leads to an error.
    > > How to access the nth element defined in the attribute
    > > CSSColorNames ??

    >
    > I think, accessing the attribute and doing tokenize() is the right
    > way. What error message are you getting?
    >
    >
    >
    > > Basically I imagine to do something like this to do this:
    > > <xsl:variable select="Agenda/@CSSColorNames[position()=2]"/>

    >
    > I think, this is not the correct way to do this.


    Hello Mukul
    The errror message is this:
    XPTY0004: A sequence of more than one item is not allowed as the
    first argument of
    tokenize() ("red", "green")
    Test lines are this ($VAgenda points to the Agende element):
    <xsl:variable name="vColorNames" select="$vAgenda/@CSSColorNames"/>
    <xsl:variable name="vSeriesColor" select="tokenize($vColorNames,'\s+')
    [position()=2]"/>
    <xsl:value-of select="$vSeriesColor"/>

    Thanks
    Rolf
    RolfK, Feb 6, 2009
    #3
  4. Re: XSLT 2.0 space separated list type access with Saxon 9.1 -sa-val

    RolfK wrote:

    > Basically I imagine to do something like this to do this:
    > <xsl:variable select="Agenda/@CSSColorNames[position()=2]"/>


    I think using the data function gives you the typed value so doing e.g.
    data(Agenda/@CSSColorNames)[2]
    should work to access the second item in the list that is the typed
    value of the CSSColorNames attribute.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 6, 2009
    #4
  5. RolfK

    RolfK Guest

    On 6 Feb., 13:34, Martin Honnen <> wrote:
    > RolfK wrote:
    > > Basically I imagine to do something like this to do this:
    > > <xsl:variable select="Agenda/@CSSColorNames[position()=2]"/>

    >
    > I think using the data function gives you the typed value so doing e.g.
    >    data(Agenda/@CSSColorNames)[2]
    > should work to access the second item in the list that is the typed
    > value of the CSSColorNames attribute.
    >
    > --
    >
    >         Martin Honnen
    >        http://JavaScript.FAQTs.com/


    Martin,

    thanks a lot! This workes fine.
    It is still not clear to me why e.g. $vAgenda/@CSSColorNames[position()
    =2] does not lead to the same result !?

    Regarding the type I tried to declare the type bt the "as" attribute.
    But this does not work. I have defined the complex type in my schema
    as shown.
    But how to use it in xslt?
    Do I have to import the schema ?

    <xsl:stylesheet version="2.0" xmlns:mgt="MarginTable" ......
    <xsl:import-schema namespace="MarginTable" schema-location="../_xsd/
    MarginTable.xsd"/>
    <xsl:template match="/">
    <xsl:variable name="vColorNames" select="$vAgenda/@CSSColorNames"
    as="mgt:tCSSColorNames"/>
    .....

    Saxon shows this error:
    XPST0051: SequenceType syntax error at char 0 in {mgt:tCSSColorNames}:
    Type (mgt:tCSSColorNames) is a list or union type

    How to declare it correctly ?

    Thanks a lot for your help

    Rolf
    RolfK, Feb 6, 2009
    #5
  6. Re: XSLT 2.0 space separated list type access with Saxon 9.1 -sa-val

    RolfK wrote:

    > It is still not clear to me why e.g. $vAgenda/@CSSColorNames[position()
    > =2] does not lead to the same result !?


    I have not much experience with schema-aware XSLT but the problem I
    think is to distinguish between selecting the second node in a step and
    the second item in the typed value of a node.
    Your expression selects the second attribute CSSColorNames. That does
    not make any sense for attributes as there can't be two attributes of
    the same type but imagine you had a 'foo' parent element and 'bar' child
    elements and then you do e.g.
    foo/bar[position() = 2]
    or
    foo/bar[2]
    that would select the second 'bar' child.
    If you wanted the typed value of the second 'bar' child then you need
    data(foo/bar[2])
    to distinguish from the earlier expression. Then on the typed value,
    assuming it is a sequence stemming from a list type, you could apply a
    predicate again:
    data(foo/bar[2])[2]



    > Regarding the type I tried to declare the type bt the "as" attribute.
    > But this does not work. I have defined the complex type in my schema
    > as shown.
    > But how to use it in xslt?
    > Do I have to import the schema ?
    >
    > <xsl:stylesheet version="2.0" xmlns:mgt="MarginTable" ......
    > <xsl:import-schema namespace="MarginTable" schema-location="../_xsd/
    > MarginTable.xsd"/>
    > <xsl:template match="/">
    > <xsl:variable name="vColorNames" select="$vAgenda/@CSSColorNames"
    > as="mgt:tCSSColorNames"/>
    > ....
    >
    > Saxon shows this error:
    > XPST0051: SequenceType syntax error at char 0 in {mgt:tCSSColorNames}:
    > Type (mgt:tCSSColorNames) is a list or union type
    >
    > How to declare it correctly ?


    The as attribute takes a sequence type, not a schema type. So you would need
    as="xs:string+"
    I think.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 6, 2009
    #6
    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. Patrick Guio
    Replies:
    6
    Views:
    3,188
    chris
    Oct 20, 2004
  2. Holger
    Replies:
    11
    Views:
    545
    Gabriel Genellina
    Feb 12, 2007
  3. Michael Neumann

    "val.dup rescue val" sloooow

    Michael Neumann, Oct 27, 2004, in forum: Ruby
    Replies:
    2
    Views:
    132
    Michael Neumann
    Oct 27, 2004
  4. Anita Anita
    Replies:
    2
    Views:
    102
    Gary Wright
    Jan 6, 2009
  5. cmic

    $hash{val} or %hash->{val} ??

    cmic, Jan 15, 2006, in forum: Perl Misc
    Replies:
    8
    Views:
    125
Loading...

Share This Page