views:

46

answers:

1

Hi,

We have in input an XML like following:

<R>
   <MT N="folder" V="Folder1\Subfolder1" />
   <MT N="folder" V="Folder2xx\Subfolder1" />
   <MT N="folder" V="Folder3yyyy\Subfolder1" />
   <MT N="folder" V="Folder4zzzz\Subfolder1" />
</R>

In our XSLT that performs the display, the entry:

<xsl:value-of select="MT[@N='folder']/@V"/>

displays:

Folder1\Subfolder1 Folder2xx\Subfolder1 Folder3yyyy\Subfolder1 Folder4zzzz\Subfolder1

What we need to achieve is to select the unique entry who starts with a pre-defined configurable list of strings, e.g. if our pre-defined list is

Folder2xx, Folder18ppp, Folder212aaa

I would like to display as output only

Folder2xx\Subfolder1

The optimal thing would be even:

Folder2xx\Subfolder1 (linked 3 times)

but I would really appreciate help on the selection of the unique element. That is unfortunately too complex for my knowledge on XSLT, can someone please help? Our system supports XSLT 2.0 and XPATH 2.0

thanks a lot!

Mario

+1  A: 

Use:

MT[@N='folder']
     /@V[substring-before(.,'\')
        =
         ('Folder2xx', 'Folder18ppp', 'Folder212aaa')
        ]
Dimitre Novatchev
@Dimitre: +1 Fast answer. I didn't see it. Deleting mine.
Alejandro
@Alejandro: Undelete it. It's not known whose one was faster :)
Dimitre Novatchev
@Alejandro: It would be unfair that mine got an upvote and yours didn't.
Dimitre Novatchev
@Dimitre: No problem. Yours was first and both looks equals: an existencial comparison against a sequence.
Alejandro
@Dimitre, thanks a lot, it works perfectly!!!
Mario
@Mario: I am happy it worked, Here at SO the established form of gratitude is accepting the answer -- this can be done by clicking the check-mark next to the answer. :)
Dimitre Novatchev
@Alejandro: Do not opt out mate -- ypurs also deserves an upvote. Undelete it.
Dimitre Novatchev