• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2635
  • Last Modified:

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

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!!
0
WJoeMoore
Asked:
WJoeMoore
  • 2
  • 2
  • 2
2 Solutions
 
kmartin7Commented:
Is the &amp; a problem in the string?
0
 
WJoeMooreAuthor 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?
0
 
Geert BormansCommented:
The way you use CDATA here is not very usefull, because the processor will see it as a text node
If you want to create a CDATA section, it needs to be in an element, attributes can't be CDATA sections

 <xsl:text disable-output-escaping="yes">&amp;</xsl:text>
is the right way to get a "&" in the output text
but that only works in elements

attributes have special rules for their content
and you can't play dirty thricks with them (as the disable output escaping)
... meaning, whatever you try, you 'll be stuck with the escaped &amp;

In short, as far as I know, this can't be done
You could hope that browsers accept the &amp; style, most of them do by now

cheers

Geert
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
WJoeMooreAuthor Commented:
It worked fine when I used 'method=post' instead of 'method=get'.  Grumble, grumble.  I still mess those up every once in awhile.
0
 
Geert BormansCommented:
have you tried escaping the URL way
%26 should be the amp
0
 
kmartin7Commented:
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now