Convert a string into Array

Here should go questions about transforming XML with XSLT and FOP.
FJJCENT
Posts: 25
Joined: Sun Apr 22, 2018 10:17 pm

Convert a string into Array

Post 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
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: Convert a string into Array

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Convert a string into Array

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
FJJCENT
Posts: 25
Joined: Sun Apr 22, 2018 10:17 pm

Re: Convert a string into Array

Post 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
Post Reply