-1

First I want to specify my goal. I am tasked to show a url concatenated to a constant string particularly '&src=JB-10081' as an attribute of xml tag in the output.

Here is my code:

    <vacancy>
        <xsl:attribute name = "url">
          <xsl:value-of disable-output-escaping="yes" select="concat(apply_url, '&amp;src=JB-10081')"/>
        </xsl:attribute>
    <vacancy>

This code gives me a result of:

 <vacancy id="6747232000011108" datestart="" dateend="" language="" origin="" url="https://dtt.taleo.net/careersection/10540/jobapply.ftl?lang=en-GB&amp;job=27050&amp;src=JB-10081">

you could notice that the URL and the string literal is shown correctly except that the output shown for the string literal was not changed to & and instead shown as &amp; can someone help me to show it as & and not &amp;

Allan Chua
  • 9,305
  • 9
  • 41
  • 61
  • 1
    There is nothing wrong with your output. An & by itself would be an error – peter.murray.rust Oct 26 '11 at 01:40
  • Hi can you please tell me why? because I need to show it as & instead of & – Allan Chua Oct 26 '11 at 01:41
  • 2
    XML has a few reserved characters including '&' . This is used to construct character entity references such as ' which is an apostrophe. Create the output you want and read it into an XML processor and it will fail to parse. Don't worry, there is a single character in there, but it cannot be displayed as & because of the XML language itself. Read a few tutorials or the spec – peter.murray.rust Oct 26 '11 at 01:44
  • 2
    @AllanChua Your output is correct. If you have a single & this is not valid xml. – FailedDev Oct 26 '11 at 01:56
  • Why does it show for other & in values but not in XML attributes? – Allan Chua Oct 26 '11 at 01:56
  • 2
    @AllanChua: You can create any text with `` . However, if you generate the text `, then the generated text isn't wellformed XML document. Remember: It is impossible to generate such wellformed XML document, because by definition, an XML document cannot contain unescaped ampersand that isn't part of an entity reference. Ony comments and processing instructions can contain such unescaped ampersand. – Dimitre Novatchev Oct 26 '11 at 02:42
  • @DimitreNovatchev I like you're answer buddy. +1 for you uhmm but it seems that i have generated a & in an element value. – Allan Chua Oct 26 '11 at 02:45
  • 2
    @AllanChua: Read the W3C XSLT 1.0 specification: You can use D-O-E to generate unescaped content *only* as part of text nodes -- not in attributes. http://www.w3.org/TR/1999/REC-xslt-19991116#disable-output-escaping "*It is an error for output escaping to be disabled for a text node that is used for something other than a text node in the result tree. Thus, it is an error to disable output escaping for an xsl:value-of or xsl:text element that is used to generate the string-value of a comment, processing instruction or attribute node*; " – Dimitre Novatchev Oct 26 '11 at 02:54
  • @DimitreNovatchev can you please put you're comment as an answer so that i could check it as the correct answer :) thanks in advance :) – Allan Chua Oct 26 '11 at 02:56

2 Answers2

2

You can use D-O-E to generate unescaped content only as part of text nodes -- not in attributes.

http://w3.org/TR/1999/REC-xslt-19991116#disable-output-escaping :

"It is an error for output escaping to be disabled for a text node that is used for something other than a text node in the result tree. Thus, it is an error to disable output escaping for an xsl:value-of or xsl:text element that is used to generate the string-value of a comment, processing instruction or attribute node; "

Community
  • 1
  • 1
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
0

I have filled out my answer above. XML has a few reserved characters including '&' . XML uses it to create entity references. Thus

<a b="&foo;"/>

instructs the XML parser to find an enntity with name 'foo'. If you don't use the &...; construct you will get an error. Try reading

<a b="&src"/>

into any XML parser and it should throw an error. So the output you wish to create is illegal XML.

If you wish to create a NON-XML string, then you will have to output as text.

peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217
  • I know this stuff buddy. But the DUMBASS clients were too insisting. lol :) – Allan Chua Oct 26 '11 at 02:02
  • 2
    If you knew the answer already then you shouldn't have asked the question. It's a waste of my time. I tried to be helpful to someone I thought would appreciate it. Please think more carefully in future – peter.murray.rust Oct 26 '11 at 02:08