How to create an array from a String

Here should go questions about transforming XML with XSLT and FOP.
Valdenir
Posts: 1
Joined: Tue Aug 07, 2018 12:28 am

How to create an array from a String

Post by Valdenir » Tue Aug 07, 2018 12:41 am

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.

Radu
Posts: 6503
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to create an array from a String

Post by Radu » Tue Aug 07, 2018 11:38 am

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply