We help IT Professionals succeed at work.

How do I code an ampersand into the value of an XML attribute using XSL?

2,683 Views
Last Modified: 2013-11-18
How do I code an ampersand into the value of an XML attribute using XSL?

Here is my XML Doc:

_____________________________

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="file:///C:/Temp/TestAmp.xsl"?>
<DocRoot>
    <KeyID>1234567</KeyID>
    <PWVerified>False</PWVerified>
    <PreReg>
        <CollID>7654321</CollID>
    </PreReg>
    <Key>100920071002274067A25D0B9D55E19ECE6EA6613BE8</Key>
</DocRoot>

_____________________________________

Here is my XSL doc:

______________________________________

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:template match="/">
        <div xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
            xmlns:fn="http://www.w3.org/2005/xpath-functions"
            xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fo="http://www.w3.org/1999/XSL/Format"
            class="uportal-channel-text">
            <xsl:choose>
                <xsl:when test="/DocRoot/PWVerified = 'True'">
                    <p>
                        <h3>everything is OK</h3>
                    </p>
                </xsl:when>
                <xsl:otherwise>
                    <p>
                        <font color="red"
                            >You must set a secret question and change your password before you can see this channel.</font>
                    </p>
                    <form method="get">
                        <xsl:attribute name="action"
                                >https://misintranet.sdstate.edu/MSOLSrv/MakeSecretQuestKey.cfm?KeyID=<xsl:value-of
                                select="/DocRoot/KeyID"
                                /><xsl:text disable-output-escaping="yes"><![CDATA[&Key=]]></xsl:text><xsl:value-of
                                select="/DocRoot/Key"/></xsl:attribute>
                        <input type="submit" value="Set secret question"/>
                    </form>
                </xsl:otherwise>
            </xsl:choose>
        </div>
    </xsl:template>
</xsl:stylesheet>

_______________________________________________________

Here is the '<form/>' statement I get:

______________________________________________________

<form method="get" action="https://misintranet.sdstate.edu/MSOLSrv/MakeSecretQuestKey.cfm?KeyID=1234567&Key=100920071002274067A25D0B9D55E19ECE6EA6613BE8"><input type="submit" value="Set secret question"/></form>

______________________________________________________

Of course, I would like a simple '&' above instead of '&amp;'.  I've tried so many combinations of <![CDATA[ and <xsl:text/> with disable-output-escaping="yes" that I can't see straight any more.  HELP!!
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Yes, when I try to submit the URL from the resulting HTML page.  Is there something else I should code in the <form/> sequence to cause it to translate it at that point?
Gertone (Geert Bormans)Information Architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
It worked fine when I used 'method=post' instead of 'method=get'.  Grumble, grumble.  I still mess those up every once in awhile.
Gertone (Geert Bormans)Information Architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
have you tried escaping the URL way
%26 should be the amp

Commented:
Take a look at http://www.w3.org/TR/1999/REC-xslt-19991116.html#section-HTML-Output-Method.

&amp; should be allowed to be used in your string.

Sorry.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.