Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

How to show & in a XML attribute That would be produced by XSLT

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;

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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; "


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...