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

R

RolfK

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
 
M

Mukul Gandhi

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.
 
R

RolfK

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
 
M

Martin Honnen

RolfK said:
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.
 
R

RolfK

RolfK said:
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,

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
 
M

Martin Honnen

RolfK said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top