Re: [xsl] Substring a Value

Subject: Re: [xsl] Substring a Value
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 9 Aug 2004 16:05:11 +0100
Hi Trevor,

> where, <xsl:value-of select="@from"/> (the value returned) needs to be
> substringed(2, len(@from)-1).

The example you gave was "ID(0DP_12345)" from which you wanted
"ODP_12345". In XPath syntax, you need:

  substring(@from, 4, string-length(@from) - 4)

The first argument is the string you want to substring. The second is
the index of the first character in the substring that you want (XPath
counts from 1 rather than 0). The third argument is the *length* of
the substring that you want.

Alternatively, you could use:

  substring-before(substring-after(@from, 'ID('), ')')

which is easier if you can't count so well!

> I have tried several JavaScripts, but I can't seem to get anything
> to work.

You're using XSLT, not Javascript. Take a look at the XPath quick
reference from: http://www.mulberrytech.com/quickref/index.html

> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl";>

Oh, I take it back, you're not using XSLT at all, but WD-xsl, the
defunct dialect once used in IE. Take a look at the MSXML FAQ at:

  http://www.netcrucible.com/xslt/msxml-faq.htm

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Current Thread