0

In the below code snippet, I am trying to get the substring of my @imageMeta node, append some more path location and pass it as a parameter to my java method through XSLT.

<xsl:variable name="imagePathFrom" select="/config/assets/images/{substring-after(@imageMeta,'/')}" />
<xsl:variable name="imagePathTo" select="'/dev/svn_root/platform/system'" />
<xsl:value-of select="filecopy:copyFile($imagePathFrom, $imagePathTo)"/>

My @imageMeta node data looks like Images/common/dialog/dialogue_black.png. I have to convert the above path to images/common/dialog/dialogue_black.png (note the change of capital 'I' to small 'i') and append some more path data.

So my final path entry should look like "/config/assets/images/common/dialog/dialogue_black.png". When i run my code snippet i get an error stating:

line 51: Error parsing XPath expression '/config/assets/images/{substring-after(@imageMeta,'/')}'.' 

Please help.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
nishMaria
  • 135
  • 3
  • 11

3 Answers3

3
<xsl:variable name="imagePathFrom" select="/config/assets/images/{substring-after(@imageMeta,'/')}" />

There are two problems here:

  1. A syntax error -- a select is probably the only attribute attribute in XSLT that cannot contain an AVT.

  2. Even without the AVT, this would attempt to select all /config/assets/images nodes, but the intent is that the variable must contain the string "/config/assets/images"

Solution to both problems:

<xsl:variable name="imagePathFrom" select=
 "concat('/config/assets/images/', substring-after(@imageMeta,'/')" />

Alternative solution:

<xsl:variable name="imagePathFrom" select=
 "concat('/config/assets/',
         translate(substring(@imageMeta, 1, 1),
                   $vUpper,
                   $vLower
                   ),
         substring(@imageMeta, 2)
         )" />

where $vLower and $vUpper are defined, respectively, as:

'abcdefghijklmnopqrstuvwxyz'

and

'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • @nishMaria: I am glad my answer was useful to you. Could you, please, consider *accepting* it (by clicking on the check-mark next to the answer)? – Dimitre Novatchev Mar 15 '12 at 12:34
2

There is one problem in your code: <xsl:variable name="imagePathFrom" select="/config/assets/images/{substring-after(@imageMeta,'/')}" />

It suppose to be .. <xsl:variable name="imagePathFrom" select="substring-after(/config/assets/images/@imageMeta,'/')" />

Rookie Programmer Aravind
  • 11,952
  • 23
  • 81
  • 114
  • This suggestion fixes the syntax, but it is not the correct one: `/config/assets/images` is the disk path, not a path in the source XML, Dimitre solution is the right one – MiMo Mar 13 '12 at 02:16
0

infant programmer 'Aravind' suggestion will solve your parse error.

You also mentioned you wanted to lower-case the capital i. Two options here:

  • Using XSLT 1.0, this StackOverflow answer explains how to lower-case the first character of a string. It won't work for Unicode characters such as 'Í' but you probably don't need it.
  • XSLT 2.0 has a lower-case function, which will lower-case your entire string, and may not be what you're looking for.
Community
  • 1
  • 1
Quentin Pradet
  • 4,691
  • 2
  • 29
  • 41