xsl-list
[Top] [All Lists]

Re: [xsl] Using variables in xpath expression

2017-07-19 08:49:23
On 19.07.2017 15:17, Joseph L. Casale jcasale(_at_)activenetwerx(_dot_)com 
wrote:
I have several templates with similar code to the following:

   <xsl:template match="wix:Component[wix:File[substring(@Source, 
string-length(@Source) - 7) = 'MyString']]">

I want to substitute 'MyString' with a variable and the 7 with a 
"string-length($var) -1"
however the processor complains about the usage of a variable. This is xsl 1 
with msxsl.

Is there any way around this so I can avoid hardcoding the string?

If you can't or don't want to move to an XSLT 2.0 processor the only option in XSLT 1 I see is matching only on
  <xsl:template match="wix:Component[wix:File]">
<xsl:if test="wix:File[substring(@Source, string-length($var) - 1) = $var2">...</xsl:if>
  </xsl:template>
Depending on other templates you have or need instead of the xsl:if you might want to use an xsl:choose/xsl:when to deal with various conditions.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>