开发者

XSLT, using the + character in a variable value

开发者 https://www.devze.com 2023-02-08 07:19 出处:网络
Is it possible to create a variable in xslt and assign it the value \"10+\"? Assigning \"10\" is fine, bu开发者_如何学Pythont when I add the + sign I get an \"Unexpected token \'<eof>\' in the

Is it possible to create a variable in xslt and assign it the value "10+" ?

Assigning "10" is fine, bu开发者_如何学Pythont when I add the + sign I get an "Unexpected token '<eof>' in the expression..." exception.


Like Max Toro said, use quotes for strings. This includes quotes inside of the "" quotes of an attribute value (such as select="").

Example:

<xsl:variable name="var" select="'10+'"/>

You can also do something like this:

<xsl:variable name="var">10+</xsl:variable>


Use quotes for strings, else the processor will think it's an expression:

'10+'


Is it possible to create a variable in xslt and assign it the value "10+" ?

Yes. This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="/">
     <xsl:variable name="vStr" select="'10+'"/>

     "<xsl:value-of select="$vStr"/>"
 </xsl:template>

</xsl:stylesheet>

when applied on any XML document (not used), produces the wanted, correct result**:

 "10+"


I think that you may not be quoting enough. Your code should look something like:

<xsl:variable name='my-var' select="'10+'"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消