开发者

special character inside of xslt string

Need to be able to pass a single quote in the string Cmm'l so it reads original xml file for that phrase. how do I do this?

<xsl:when test="contains(ct-type/cat开发者_StackOverflow中文版s, 'Cmml') or contains(ct-type/cats, 'rst')">
<xsl:element name="Terms">
<xsl:value-of select="'example'"/>
</xsl:element>
</xsl:when>


You can use apostrophes as attribute value delimiters and then use an entity inside the string:

<xsl:when test='contains(ct-type/cats, "Cmm&apos;l") or contains(ct-type/cats, "rst")'>

If you need both quotes and apostrophes in the string, then you can use e.g. variables for the strings or punctuation.


You can pass the value as either a variable or a parameter.

I'm sure there is a much better way to do this, but I can't think of it right now.

Here's an example of passing it as a parameter with default values:

  <xsl:template match="doc">
    <xsl:param name="cat_type_1">
      <xsl:text>Cmm'l</xsl:text>
    </xsl:param>
    <xsl:param name="cat_type_2">
      <xsl:text>rst</xsl:text>
    </xsl:param>
    <xsl:if test="contains(ct-type/cats, $cat_type_1) or contains(ct-type/cats, $cat_type_2)">
      <Terms>Example</Terms>
    </xsl:if>
  </xsl:template>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜