xsl-list
[Top] [All Lists]

Re: [xsl] How to overrite default rendering toretain name=value attribute pairs

2007-06-19 05:56:47
Thanks Mr.David. I tried what your suggested but could not really make
it to work. 

1) On 
It should be selected=selected (which may be serialised 
as just selected in html)

Actually my first try was with selected=selected, after failing with it,
tried selected=true. I both cases, the resultant output got serialized
to output  <option selected>


that is a bug in your XSLT engine. 
If so, any alternative way possible? We work in php environment. Sorry,
so far I am unable to get more info of the xsl engine.

If you are using the XML output type <xsl:output method="xml"/> 
which is what you want to use, given your requirement to 
generate well formed xml) then this attribute minimisation 
should never happen

So far we used <xsl:output method="html"/>, but just tried with
output=xml option but still it gets serialized to output without =true.
By the way, we may have to use output=html for other reasons.


if you are using the html output.... but
<option selected = "true"> should be 
serialised as <option selected = "true">

This seems not happening. 

 (selected=true) a selected="true" is not valid 
html or xhtml (although xslt will generate it if you want).

As you said, we would like xslt to generate this way <option
selected="true">. Pls can you suggest how we can force it to get this?

Sample XML code:
<ANSWER QTYPE="MATCH">
        <CHOICE ID="1">
                <CONTENT TYPE="text/html"><![CDATA[glove]]></CONTENT>
                <OPTION SELECTED="true"><![CDATA[head]]></OPTION>
                <OPTION><![CDATA[hand]]></OPTION>
                <OPTION><![CDATA[foot]]></OPTION>
        </CHOICE>
        <CHOICE ID="2">
                <CONTENT TYPE="text/html"><![CDATA[sock]]></CONTENT>
                <OPTION><![CDATA[head]]></OPTION>
                <OPTION><![CDATA[hand]]></OPTION>
                <OPTION><![CDATA[foot]]></OPTION>
        </CHOICE>
        <CHOICE ID="3">
                <CONTENT TYPE="text/html"><![CDATA[hat]]></CONTENT>
                <OPTION><![CDATA[head]]></OPTION>
                <OPTION SELECTED="true"><![CDATA[hand]]></OPTION>
                <OPTION><![CDATA[foot]]></OPTION>
        </CHOICE>
</ANSWER>

Desired output: (for each choice group)

<script type="text/javascript"> 
        inputXML += '<CHOICE id="answer_xx">\n';
        inputXML += '<option SELECTED="TRUE">head</option>\n';
        inputXML += '<option>hand</option>\n'; 
        inputXML += '<option>foot</option>\n'; 
        inputXML += '</CHOICE>\n';
</script>

Pls ignore any type error / case sensitive mistakes. Thanks in adv.
karl

------------------------------

Date: Fri, 15 Jun 2007 13:43:06 +0100
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
Subject: Re: [xsl] How to overrite default rendering toretain
name=value attribute pairs
Message-Id: 
<200706151243(_dot_)l5FCh66H011089(_at_)edinburgh(_dot_)nag(_dot_)co(_dot_)uk>

 (selected=true) a

selected="true" is not valid html or xhtml (although xslt will generate
it if you want).

It should be selected=selected (shich may be serialised as just selected
in html)

Results in <option selected>xxx</option>, without ="TRUE" thereby
becoming an INVALID XML

that is a bug in your XSLT engine. If you are using the XML output type
<xsl:output method="xml"/>
which is what you want to use, given your requirement to generate well
formed xml) then this attribute minimisation should never happen.
if you are using the html output
<xsl:output method="html"/>
then 
<option selected="selected">
may be (and probably would be) serialised as
<option selected>
but
<option selected = "true">
should be serialised as
<option selected = "true">

David




Date: Fri, 15 Jun 2007 08:35:19 -0400
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
From: "Karlmarx Rajangam" 
<karlmarx(_dot_)rajangam(_at_)questionmark(_dot_)co(_dot_)uk>
Subject: How to overrite default rendering toretain  name=value
attribute pairs
Message-ID:
<6B219F1619B1EB449A246CFA95A8CA29AC0432(_at_)coint-wexchp1(_dot_)questionmark(_dot_)local


I have a problem. Basically I want to get an output with =
selected=3D"true"
for <option/>, instead of WITHOUT "true". Even though <option selected/>
is a valid html, I need to get name=3Dvalue pair (selected=3Dtrue) as we
=
try
to form & pass an XML input for some other validation.=20

We must create something like,
<choice>
        <option selected =3D "true">cc</option>
        <!-- NOT THIS WAY <option selected>cc</option> -->
        <option>bbb</option>
</choice>

Tried 2 ways:(A)
<xsl:for-each select=3D"OPTION">
inputXML +=3D '<option>
        <xsl:if test=3D"@SELECTED=3D'true'"><xsl:attribute
name=3D"Selected">true</xsl:attribute></xsl:if><xsl:value-of =
select=3D"."/>
</option>\n';
</xsl:for-each>

Results in <option selected>xxx</option>, without =3D"TRUE" thereby
becoming an INVALID XML

So, I tried (B),=20
<xsl:for-each select=3D"OPTION">
<xsl:choose>
        <xsl:when test=3D"@SELECTED=3D'true'">inputXML +=3D '&lt;option
selected=3D"true"&gt;<xsl:value-of
select=3D"."/>&lt;/option&gt;\n';</xsl:when>
        <xsl:otherwise>inputXML +=3D '<option><xsl:value-of
select=3D"."/></option>\n';</xsl:otherwise>
</xsl:choose>
</xsl:for-each>=09

thinking &lt; will be rendered a <, but resulted only as=20
&lt;option selected=3D"true"&gt;xxx&lt;/option&gt;

Any suggestion how I can fix this? =20

Thanks in advance,
karl

=20




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>