Copied to clipboard

Flag this post as spam?

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

  • jacob phillips 130 posts 372 karma points
    May 21, 2014 @ 01:50
    jacob phillips

    replace & with &

    I have a macro that makes API calls.

    The API urls are generated by an outside system. This outside system strings together query params using a single ampersand.

    The url is passed as a macro param.

    What I want to do is replace the ampersands with &

    I tried this:

    <xsl:variable name="APICALL" select="umbraco.library:Replace($APICALLUrlRaw, '&', '&amp;')" />

    But I just get:

        Error occured
    System.Xml.XmlException: An error occurred while parsing EntityName. Line 28, position 80.
    at System.Xml.XmlTextReaderImpl.Throw(String res, Int32 lineNo, Int32 linePos)
    at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos)
    at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
    at System.Xml.XmlTextReaderImpl.ParseAttributes()
    at System.Xml.XmlTextReaderImpl.ParseElement()
    at System.Xml.XmlTextReaderImpl.ParseElementContent()
    at System.Xml.Xsl.Xslt.XsltInput.ReadTextNodes()
    at System.Xml.Xsl.Xslt.XsltInput.ReadNextSibling()
    at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags)
    at System.Xml.Xsl.Xslt.XsltLoader.LoadTemplate(NsDecl stylesheetNsList)
    at System.Xml.Xsl.Xslt.XsltLoader.LoadRealStylesheet()
    at System.Xml.Xsl.Xslt.XsltLoader.LoadDocument()
    at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)

    I tried to disable the output escaping:

    <xsl:output method="html" omit-xml-declaration="yes"/>
  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    May 21, 2014 @ 02:05
    Chriztian Steinmeier

    Hi Jacob,

    Depending on where the string is used, you may not even need to escape it - but if you have to, you need to escape the ampersands you're using. Yes, it's tricky, but you're doing the equivalent of including a double-quote character in a double-quoted string. The ampersand is special in XML, so you need to escape it:

    <xsl:variable name="APICALL" select="umbraco.library:Replace($APICALLUrlRaw, '&amp;', '&amp;amp;')" />


  • jacob phillips 130 posts 372 karma points
    May 22, 2014 @ 00:05
    jacob phillips

    It is used in


    I did not test it again, but I recall from when I first did the macro that the raw ampersand broke it.

    Nevertheless, the replacement you have suggested works. Awesome.

Please Sign in or register to post replies

Write your reply to: