vulcan raven
vulcan raven

Reputation: 33572

XSLT: XPath 1.0 substring

Using XPath 1.0 in XSLT SharePoint 2013, I have two objectives:

  1. To extract 'Library Name' from:

    /path/to/library/could/be/any/length/Library Name/file.extension

  2. To extract document id QYZM2HKWQCSZ-3-3 from the following:

    http://sharepoint01/sites/temp/_layouts/15/DocIdRedir.aspx?ID=QYZM2HKWQCSZ-3-3, QYZM2HKWQCSZ-3-3

How to extract the desired strings?

OAN, for some reason Document Id column return the full blown path to the resource as opposed to Id only.

Any suggestions, how to get Id only (to avoid substring preprocessing)?

Upvotes: 1

Views: 733

Answers (2)

Jens Erat
Jens Erat

Reputation: 38682

  1. Not possible in plain XPath 1.0 if you cannot find any further pattern in the path.
  2. It seems the pattern ?ID= is fixed, and also the colon following the ID. If so, you can use substring-after(substring-before(., ','), '?ID='). Replace the context . by some XPath expression selecting the string.

Upvotes: 1

Michael Kay
Michael Kay

Reputation: 163322

For (1), write a recursive template as follows. Pass the input string as a parameter.

(a) if not(contains(substring-after($input, '/'), '/')) then return substring-before($input, '/')

(b) otherwise, make a recursive call passing (substring-after($input, '/')) as the parameter.

(c) add some error-handling logic to make sure you terminate if the input string doesn't contain a '/'.

Upvotes: 2

Related Questions