Hobbes
Hobbes

Reputation: 2115

How do I address an item in a sequence when using tokenize()

I have an HTML that contains a style attribute with a list of values separated by semicolons:

<td style="border-width:1pt;border-color:#FFFFFF;border-style:solid">

I want to split this list:

<xsl:variable name="astyle"><xsl:value-of select="tokenize(@style, ';')"/></xsl:variable>

This gives me a sequence. Now I want to select the first item in the sequence.

<xsl:value-of select="$astyle[1]"/>

result: "border-width:1pt border-color:#FFFFFF border-style:solid"

so that's the entire sequence instead of the first item in the sequence.

I can't find any documentation on this.

Edit: it seems my assumption is incorrect. Tokenize() contains a sequence of 1 item. I was expecting 3 items.

How can I split a string into items that can be addressed individually? I want to do something like

<xsl:value-of select="$astyle[1]"/>

and get:

border-width:1pt

Upvotes: 1

Views: 304

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167516

Use <xsl:variable select="tokenize(...)" name="astyle"/>, then the value of the variable is a sequence and $astyle[1] works.

Upvotes: 2

Related Questions