如何在<xsl:apply-templates>中使用Apostrophe选择</xsl:apply-templates>

时间:2014-01-30 11:25:33

标签: xslt escaping

我必须在tag的select属性中添加Apostrophe(')。

喜欢这个

<xsl:apply-templates select="Object[@class='name of' class']" mode="name of' class" />

班级名称中有撇号(')。这里介于名称和类之间。

3 个答案:

答案 0 :(得分:2)

在XSLT 2.0中,您可以将用于字符串文字的分隔符加倍:

select="Object[@class='name of'' class']"

如果要转义用于包含属性的分隔符,请使用XML实体引用。 (这些用于转义字符串分隔符没有用,因为它们在XPath解析器看到它们之前被展开)。

在XSLT 1.0中无法转义字符串分隔符。最好的方法是使用变量:

<xsl:variable name="x">name of' class</xsl:variable>
<xsl:apply-templates select="Object[@class=$x]"/>

答案 1 :(得分:1)

我想你想要<xsl:apply-templates select="Object[@class=&quot;name of' class&quot;]"。这样,您可以将class属性值与字符串文字name of' class进行比较。使用XSLT / XPath 2.0,您也可以编写<xsl:apply-templates select="Object[@class='name of'' class']"

答案 2 :(得分:0)

尝试:

select='Object[@class="name of&#39; class"]'