Page 1 of 1

How to create an array from a String

Posted: Tue Aug 07, 2018 12:41 am
by Valdenir
Hi there.
Please, I need help on this, I have this XML tag :
<productsSDWAN_quote>
SD-WAN (30 MB / EDGE 510)$,$SD-WAN GATEWAY 30 MB$,$SD-WAN GATEWAY 100 MB$,$SD-WAN (30 MB / EDGE 510)$,$SD-WAN GATEWAY 30 MB$,$SD-WAN GATEWAY 100 MB$,$
</productsSDWAN_quote>

I used split to split it.
<xsl:variable xmlns:str="http://exslt.org/strings" name="products" select="str:split($main_doc/productsSDWAN_quote, '$,$')"/>

I need create new array with only the products that contains the word "GATEWAY" at its names.
How can I do that using for-each loop through products and catch only the "GATEWAY" ones and create a new list with them?

thanks.

Re: How to create an array from a String

Posted: Tue Aug 07, 2018 11:38 am
by Radu
Hi,

Probably instead of the old xslt split utilities you could use the XSLT 2.0 tokenize function. Then wrap each interesting text in an <item> element and have the list of items returned in the variable for further use:

Code: Select all

    <xsl:template match="productsSDWAN_quote">
<xsl:variable name="myInterestingVals">
<xsl:for-each select="tokenize(text(), '\$,\$')">
<xsl:if test="contains(., 'GATEWAY')">
<item>
<xsl:copy-of select="."/>
</item>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="$myInterestingVals/*/text()">
<xsl:message>VAL <xsl:value-of select="."/></xsl:message>
</xsl:for-each>
</xsl:template>
Regards,
Radu