XSLT: Define a param with & ampersand
I need to define a xsl:param
with a string that contains &
character for further processing.
For example:
<xsl:param name="greeting" as="xs:str开发者_JAVA百科ing">Hi & Bye</xsl:param>
Important Notice:
I am using a xslt converter component in a webservice tool. What I do, is that I just initialize the param
and as the webservice is called the param
is set to a value of a variable which was set in previous steps. So I have no control on the string, i.e meaning I can't use &
Any ideas how to do that?
Thanks in advance.
Encode it.
&
is encoded as &
:
<xsl:param name="greeting" as="xs:string">Hi & Bye</xsl:param>
See this document about XML Character entities.
Another option is to enclose such strings in CDATA
sections:
<xsl:param name="greeting" as="xs:string"><![CDATA[Hi & Bye]]></xsl:param>
You could attempt to store the string as unparsed character data (CDATA). Marking the string in that case will notify an XML parser that the contained information should not be parsed:
<xsl:param name="greeting" as="xs:string"><![CDATA[ Hi & Bye ]]></xsl:param>
精彩评论