Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Arnim Anhut 137 posts 148 karma points
    Jul 22, 2009 @ 18:16
    Arnim Anhut
    0

    How to get the Ampersand output as single char?

    Hello,

    I'm trying to write an XSLT for using ImageGen. Everything works quite well, but I just don't seem to find any way to get the Ampersand (&) output as a single char and not as &

    I used <xsl:text disable-output-escaping="yes">&amp;</xsl:text> but it just gives me &amp;

    I guess its totaly simple but I don't find how!

    Looking forward for your help,

    Arnim.

  • dandrayne 1138 posts 2262 karma points
    Jul 22, 2009 @ 18:34
    dandrayne
    0

    Use

    &#160;

    when in xslt

    Dan

  • dandrayne 1138 posts 2262 karma points
    Jul 22, 2009 @ 18:34
  • Arnim Anhut 137 posts 148 karma points
    Jul 22, 2009 @ 18:42
    Arnim Anhut
    0

    @Dan: Won't work &#160; shows nothing and using &#36; I get &amp; on the output side again.

    Do I have to set a specific out-format or some escaping or something?

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Jul 22, 2009 @ 19:15
    Douglas Robar
    0

    There's a looong discussion about this on the old forum. Here's the summary...

    The & character is not a valid character by itself in XSLT, there is only the &amp; sequence. No good way around that.

    When creating querystring parameters (for ImageGen, for instance) you want to have something like:

    http://localhost/umbraco/imagegen.ashx?test=hello&color=red

    But with XSLT you'll only ever get the following:

    http://localhost/umbraco/imagegen.ashx?test=hello&amp;color=red

     

    UNLESS... you change your xslt output method to 'html'.

    <xsl:output method="html" omit-xml-declaration="yes"/>

     

    cheers,
    doug.

  • Arnim Anhut 137 posts 148 karma points
    Jul 22, 2009 @ 19:31
    Arnim Anhut
    0

    @Doug: I already tried this, but everything I get is &amp; doesn't matter if I use &amp; directly oder inside a <xsl:text disable-output-escaping="yes">&amp;</xsl:text>

    But it must be possible anyhow I can't be the only one trying this?!?

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 22, 2009 @ 19:45
    Sebastiaan Janssen
    1

    Arnim, in a URL it's totally valid to actually use "&amp;". What's the specific reason tha you need to output just a single ampersand? 

    To be honest, I've never found any reason to require that.

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Jul 22, 2009 @ 19:46
    Douglas Robar
    2

    Sorry, had a brain cramp while typing the summary of the situation. I don't know what I was saying with the output method... not relevant.

    The real conclusion is...

    There is NO problem with having the '&amp' appear on the querystring. Every browser will support it just as if it were only the '&' character.

    For instance, I do this kind of thing all the time and it works in every browser I've ever tested it on:

    <img class="hcgThumbWrapper" src="/umbraco/imagegen.ashx?image={$topic}.jpg&amp;class=hcgThumbWrapperHome" />

     

    So, don't worry about the expanded ampersand; it's just fine even though it looks a bit ugly.

    cheers,
    doug.

     

  • Arnim Anhut 137 posts 148 karma points
    Jul 22, 2009 @ 20:01
    Arnim Anhut
    0

    Aw... I'm such a fool... your're right - off course - both of you. I just had a dumb misstype in my line and thought the error was caused by the &amp;'s!

    Sorry to bother you and big big thanx for helping!

    Greets, Arnim.

  • Petr Snobelt 923 posts 1535 karma points
    Jul 23, 2009 @ 08:57
    Petr Snobelt
    3

    BTW there (of course) is way how to write it :-)

    <xsl:variable name="and"><![CDATA[&]]></xsl:variable>
    <xsl:value-of select="concat('umbraco is great ', $and, ' powerfull')"
     disable-output-escaping="yes"/>

    Petr

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jul 23, 2009 @ 11:07
    Peter Dijksterhuis
    0

    @Petr 

    Thanks for that snippet. I also thought I saw something to be added to the ENITY at top of the xslt-file which could also solve this (just like there's the nbsp), did look for it yesterday but couldn't find it.

  • Petr Snobelt 923 posts 1535 karma points
    Jul 23, 2009 @ 16:19
  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jul 23, 2009 @ 16:20
    Peter Dijksterhuis
    0

    Yes, that was it! Thnx

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Jul 23, 2009 @ 17:52
    Douglas Robar
    0

    Because &amp; is a built-in character and the '&' symbol is a marker of the beginning of entities I don't think you can short-circuit the &amp; in xslt. There's a small discussion of entities in my blogpost about the "Anatomy of an umbraco XSLT file" (http://blog.percipientstudios.com/2009/4/11/anatomy-of-an-umbraco-xslt-file.aspx). You'll see that &amp; is one of the five built-in entities.

    Still, if anyone finds a way to do it, I'd love to hear about it!!

    cheers,
    doug.

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 24, 2009 @ 22:58
    bob baty-barr
    0

    okay, i know i saw something somewhere about the & and inline xslt when it is related to imagegen stuff... but can't find it to save my life... little help?

  • bob baty-barr 1180 posts 1294 karma points MVP
    Aug 24, 2009 @ 23:07
    bob baty-barr
    0

    found it...

    To insert an ampersand in inline xslt you must use &amp;amp;

    This is quite a common problem when doing complex XML type encoding.

    So you need to write,

    &amp;amp;height=200&amp;amp;width=500 ... Etc

  • Ansar 181 posts 291 karma points
    Sep 29, 2012 @ 13:01
    Ansar
    0

    I am getting XML data from an external service which already has the ampersand as &amp; - now XSLT converts it into &amp;amp; 

    Is there any solution for this.. 

  • siddharth 2 posts 71 karma points
    Jan 25, 2017 @ 09:45
    siddharth
    0

    I am also facing the same issue. My external XML comes line

    If you found solution for this please let me know.

    Admin please direct me to the link if the issue is already resolved.

    thanks Siddharth

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 01, 2012 @ 09:02
    Chriztian Steinmeier
    0

    Hi Anz,

    If you create a new thread for this, you can be more specific and post some code; and more people will see it, thus being able to help you with your specific version of this problem.

    /Chriztian

  • siddharth 2 posts 71 karma points
    Jan 25, 2017 @ 09:49
    siddharth
    0

    Can you redirect me to the new thread which was created for the issue highlighted by anz.

    thanks siddharth

  • himabindu-veganur-dc-gov 1 post 21 karma points
    Jul 24, 2023 @ 21:42
    himabindu-veganur-dc-gov
    0

    Do we have a solution for & to be passed as &

Please Sign in or register to post replies

Write your reply to:

Draft