views:

55

answers:

3

hi i am trying to write a regular expression inside an xslt but i have a problem with the " sign. i closes the attribute. and \" dosnt seem to work like it works in aspx pages

here is my code:

<xsl:if test="@text = 'yes'">
  <asp:RegularExpressionValidator runat="server" ControlToValidate="{@name}" 
   ValidationExpression="^[\w '%+*.!=/\\\[\]\{\}\?\,\(\)-]+$"
   ErrorMessage=" " Display="Dynamic">
      <span class="red_star">*</span>
  </asp:RegularExpressionValidator>
</xsl:if>

how can i add the " sign to the regular expression? so it will be like this:

ValidationExpression="^[\w '%+*.!=/\[]{}\?\,()\"-]+$"

thank you

+3  A: 
Oded
Isn't that `"`?
Kobi
@kobi, corrected
klez
Escaping `>` is usually not required (only matters sometimes within a CDATA). Also, one of `"` or `'` can be left unescaped if the other character isn't present in the string (the other character can be used as the string delimiter).
Dimitre Novatchev
+3  A: 

You should be able to express " with the xml entity &quot;

davidi
A: 

Since you're generating another XML document (or aspx, or HTML, for that matter), I believe you need a little more encoding. For the example, suppose you want attribute to be abc"edf:

attr="abc&quot;edf", as suggested, will cause the XSL engine to see the text as attr="abc"edf". In this case, the XSL is valid, but the generated document isn't!.

What you probably need here is:

attr="abc&amp;quot;edf"

Here, the XSL engine sees and generates attr="abc&quot;edf" - that is, you want &quot; to be part of the output, not the input.


alt text

(As an alernative, you might get away with single quotes: attr='abc&quot;edf' - this wouldn't help here though, because you also have a single quote in your string...)

Kobi
Your answer is misleading and untrue. This is not how the XSL engine works. The XSL engine is, as expected, XML-aware. This means that when it generates the document, it first generates an XML tree which is THEN serialized into an XML string if needed (often it isn't)So, first, the XML and XSL documents are parsed into XML objects. At this point, the literal value of attribute "attr" is parsed and stored as: abc"edf. Then that attribute value is set to the result document attribute again literally, i.e. resulting abc"edf when serialized. Try it in any XSL engine and see for yourself :-)
dionyziz
Kobi