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.

0

3 Answers 3

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'
Sign up to request clarification or add additional context in comments.

1 Comment

@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)?
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,'/')" />

1 Comment

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
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.