Page 1 of 1

Convert a string into Array

Posted: Fri Jun 01, 2018 12:41 pm
by FJJCENT
Hi everybody, I have an small problem with my code and I think it is not very complicated but I donĀ“t find any solution for it in Internet, my questios is that I have a single string data in a variable defined as xs:string <variable name="data" as="xs:string" select="string('Spain')" /> and I need to call to a function which expect to receive an xs:string* as parameter (an Array) but how can I convert my simple string in one Array without using Tokenize which is not compatible wit the .NET API.

[<variable name="data" as="xs:string" select="string('Spain')" /> --> this is my data

<xsl:function name="receptor"> --> and I want co call this function
<xsl:param name="Countries" as="xs:string*" />
<xsl:sequence ....
</xsl:function[/b]>

Best Regards

Re: Convert a string into Array

Posted: Mon Jun 04, 2018 11:07 am
by Radu
Hi,

Maybe you can build your own "tokenize" template:

https://www.oxygenxml.com/archives/xsl- ... 00939.html

then maybe save in a variable the result of the tokenization and apply an XPath on the variable to return only the texts content of the <token> elements.

Regards,
Radu

Re: Convert a string into Array

Posted: Mon Jun 04, 2018 11:31 am
by adrian
Hi,

I would not call xs:string* an array, it's actually a sequence of strings, xs:string (0 to many). If your xs:string has a single value, normally you shouldn't have to convert a single xs:string to a sequence yourself. AFAIK Saxon converts it automatically.
But anyway, you can just pass as argument "($data)". This is a sequence of just one xs:string with the value of $data.
Or you can use a variable of type xs:string*, like this:

Code: Select all

<xsl:variable name="seq" as="xs:string*" select="($data)"/>
You can ignore this, if your xs:string has multiple values separated by space that need to be tokenized (separated) into multiple strings.

Regards,
Adrian

Re: Convert a string into Array

Posted: Thu Jun 07, 2018 12:07 pm
by FJJCENT
that's ok, I've checked sending a simple string and it worked, the problem was that i had an error in the following line and I thought that it was in this line, but sending a simple string to parameter marked as string* doesn't yield any error.

Best Regards