Re: [xslt] Close brace in literal terminates expression in attribute value template



Hi Phil,

Phil Shafer schrieb am 28.06.2010 um 16:50 (-0400):
> What is the proper way to use a literal close brace within an
> expression inside an attribute value template?
> 
>       <e a="{substring-before($v, '}')}"/>
> 
> The spec says:
> 
>   http://www.w3.org/TR/xslt#attribute-value-templates
> 
>     A right curly brace inside a Literal in an expression is not
>     recognized as terminating the expression.
> 
> But this does not seem to be the case.  In the example below, a
> substring-before() invocation using '{' works, but using '}' gives
> an error.

This works fine for me.

> The same section of the spec says:
> 
>     When an attribute value template is instantiated, a double left or
>     right curly brace outside an expression will be replaced by a
>     single curly brace. It is an error if a right curly brace occurs
>     in an attribute value template outside an expression without being
>     followed by a second right curly brace.
> 
> So using double braces ("}}") should not work, since the
> doubling-as-escape only works outside expressions.  I tested it and
> it also fails, since the expression is terminated on the first close
> brace.

Not sure what you're doing and seeing here.

Here's another version of your stylesheet as a check:

$ expand -t2 /tmp/t.xsl
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output indent="yes"/>
  <xsl:variable name="v" select="'before{during}after'"/>
  <xsl:template match="/">
    <top>
      <e a="{$v}"/>
      <xsl:comment> { </xsl:comment>
      <e a="{substring-before($v, '{')}"/>
      <xsl:comment> } </xsl:comment>
      <e a="{substring-before($v, '}')}"/>
      <xsl:comment> {{ and }} </xsl:comment>
      <e a="{{ double curly works for me }}"/>
    </top>
  </xsl:template>
</xsl:stylesheet>

$ xsltproc /tmp/t.xsl /tmp/t.xsl
<?xml version="1.0"?>
<top>
  <e a="before{during}after"/>
  <!-- { -->
  <e a="before"/>
  <!-- } -->
  <e a="before{during"/>
  <!-- {{ and }} -->
  <e a="{ double curly works for me }"/>
</top>

$ xsltproc --version
Using libxml 20707, libxslt 10126 and libexslt 815
xsltproc was compiled against libxml 20707, libxslt 10126 and libexslt 815
libxslt 10126 was compiled against libxml 20707
libexslt 815 was compiled against libxml 20707

-- 
Michael Ludwig


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]