You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by mahati <rm...@gmail.com> on 2009/07/07 09:27:30 UTC

XSL:VALUE-OF

I have a template say, columnHeader which i am calling as below in a xsl:

<xsl:call-template name="columnHeader">
<xsl:with-param name="value">&lt;a id="frameLoader"
href="javascript:void(0);" onclick="javascript:<xsl:value-of
select="$gridName"/>.expandAllTreeRows(this);"&gt;+&lt;/a&gt;</xsl:with-param>
</xsl:call-template>

Inside the template apart from other stuff, i print the value using
xsl:value as below:

<xsl:value-of select="$value"/>

This code was working fine before migrating to Xalan 2.7.1. But, once i
moved to Xalan 2.7.1, text in the value variable is getting printed as
normal text, it's not being treated as html and hence not being rendered as
a href in the browser. Instead i get something like  javascript:void(0); + 
as plaint text.

Please suggest.
-- 
View this message in context: http://www.nabble.com/XSL%3AVALUE-OF-tp24368424p24368424.html
Sent from the Xalan - J - Users mailing list archive at Nabble.com.


Re: XSL:VALUE-OF

Posted by Michael Ludwig <ml...@as-guides.com>.
mahati schrieb:
> Following is a param to a template
>
> <xsl:with-param name="value">&lt;a id="frameLoader"
> href="javascript:void(0);" onclick="javascript:<xsl:value-of
> select="$gridName"/>.expandAllTreeRows(this);"&gt;+&lt;/a&gt;</xsl:with-param>

That's plain wrong. You're falling back to your initial mistake.
I suggest you reread the answers Christoffer and I gave you. Or
read a good book on XSLT to overcome wrong concepts you seem to
have acquired.

Cheers,

Michael Ludwig

Re: XSL:VALUE-OF

Posted by mahati <rm...@gmail.com>.
Hi Chris,

Problem hear is i can't use '<a' as i have a onclick attribute on href which
takes value from '<xsl:value-of select="$gridName"/>', so i used '&lt;' and
'&gt;'. But, giving these making it considered as normal text instead of a
node.

thanks,
ravi.


Christoffer Dam Bruun wrote:
> 
> Hi mahati,
> 
> I believe you must write:  + 
> 
> Instead of : &lt;a id="frameLoader" ...>+&lt;/a&gt;
> 
> Otherwise you do not create an element in the result tree, but only a
> text.
> 
> /Christoffer Bruun
> 
> 
> mahati skrev:
>> Following is a param to a template
>>
>> <xsl:with-param name="value">&lt;a id="frameLoader"
>> href="javascript:void(0);" onclick="javascript:<xsl:value-of
>> select="$gridName"/>.expandAllTreeRows(this);"&gt;+&lt;/a&gt;</xsl:with-param>
>>
>> Then, within the template, i have:
>>
>> <xsl:copy-of select="$value"/>
>>
>> This makes template to print:
>>
>> javascript:void(0); + 
>>
>> But, the problem is that browser just prints this as raw text instead of
>> interpreting as href element.
>>
>> You can observe that entire output is being captured correctly but gets
>> printed as raw text instead of being treated as html.
>>
>> thanks,
>> mahati.
>>
>>
>> Michael Ludwig-4 wrote:
>>   
>>> mahati schrieb:
>>>
>>>     
>>>> I tried using xsl:copy-of, but it's printing html as raw text to the
>>>> browser
>>>>       
>>> That doesn't make sense. <xsl:copy-of select="$rtf"/> should copy the
>>> RTF to the output. Could you post an example?
>>>
>>>     
>>>> Requirement here is to build a href dynamically and show it. Do you
>>>> mean 'a' tag  is ignored by Xalan 2.7.1, by the way, this problem is
>>>> showing up only after we migrated to 2.7.1.
>>>>       
>>> Xalan doesn't know about tags, it knows about element nodes. I don't
>>> think   elements are treated specially.
>>>
>>>     
>>>> Please suggest.
>>>>       
>>> I think I've already suggested a solution. Does it not work?
>>>
>>> Michael Ludwig
>>>
>>>
>>>     
>>
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/XSL%3AVALUE-OF-tp24368424p24603574.html
Sent from the Xalan - J - Users mailing list archive at Nabble.com.


Re: XSL:VALUE-OF

Posted by mahati <rm...@gmail.com>.
Hi Chris,

I tried both ways, but the same result, only text is being written.

thanks,
ravi.


Christoffer Dam Bruun wrote:
> 
> Hi mahati,
> 
> I believe you must write:  + 
> 
> Instead of : &lt;a id="frameLoader" ...>+&lt;/a&gt;
> 
> Otherwise you do not create an element in the result tree, but only a
> text.
> 
> /Christoffer Bruun
> 
> 
> mahati skrev:
>> Following is a param to a template
>>
>> <xsl:with-param name="value">&lt;a id="frameLoader"
>> href="javascript:void(0);" onclick="javascript:<xsl:value-of
>> select="$gridName"/>.expandAllTreeRows(this);"&gt;+&lt;/a&gt;</xsl:with-param>
>>
>> Then, within the template, i have:
>>
>> <xsl:copy-of select="$value"/>
>>
>> This makes template to print:
>>
>> javascript:void(0); + 
>>
>> But, the problem is that browser just prints this as raw text instead of
>> interpreting as href element.
>>
>> You can observe that entire output is being captured correctly but gets
>> printed as raw text instead of being treated as html.
>>
>> thanks,
>> mahati.
>>
>>
>> Michael Ludwig-4 wrote:
>>   
>>> mahati schrieb:
>>>
>>>     
>>>> I tried using xsl:copy-of, but it's printing html as raw text to the
>>>> browser
>>>>       
>>> That doesn't make sense. <xsl:copy-of select="$rtf"/> should copy the
>>> RTF to the output. Could you post an example?
>>>
>>>     
>>>> Requirement here is to build a href dynamically and show it. Do you
>>>> mean 'a' tag  is ignored by Xalan 2.7.1, by the way, this problem is
>>>> showing up only after we migrated to 2.7.1.
>>>>       
>>> Xalan doesn't know about tags, it knows about element nodes. I don't
>>> think   elements are treated specially.
>>>
>>>     
>>>> Please suggest.
>>>>       
>>> I think I've already suggested a solution. Does it not work?
>>>
>>> Michael Ludwig
>>>
>>>
>>>     
>>
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/XSL%3AVALUE-OF-tp24368424p24371448.html
Sent from the Xalan - J - Users mailing list archive at Nabble.com.


Re: XSL:VALUE-OF

Posted by Christoffer Dam Bruun <cd...@flyingpigs.dk>.
Hi mahati,

I believe you must write: <a id="frameLoader" ......>+</a>

Instead of : &lt;a id="frameLoader" ...>+&lt;/a&gt;

Otherwise you do not create an element in the result tree, but only a text.

/Christoffer Bruun


mahati skrev:
> Following is a param to a template
>
> <xsl:with-param name="value">&lt;a id="frameLoader"
> href="javascript:void(0);" onclick="javascript:<xsl:value-of
> select="$gridName"/>.expandAllTreeRows(this);"&gt;+&lt;/a&gt;</xsl:with-param>
>
> Then, within the template, i have:
>
> <xsl:copy-of select="$value"/>
>
> This makes template to print:
>
> javascript:void(0); + 
>
> But, the problem is that browser just prints this as raw text instead of
> interpreting as href element.
>
> You can observe that entire output is being captured correctly but gets
> printed as raw text instead of being treated as html.
>
> thanks,
> mahati.
>
>
> Michael Ludwig-4 wrote:
>   
>> mahati schrieb:
>>
>>     
>>> I tried using xsl:copy-of, but it's printing html as raw text to the
>>> browser
>>>       
>> That doesn't make sense. <xsl:copy-of select="$rtf"/> should copy the
>> RTF to the output. Could you post an example?
>>
>>     
>>> Requirement here is to build a href dynamically and show it. Do you
>>> mean 'a' tag  is ignored by Xalan 2.7.1, by the way, this problem is
>>> showing up only after we migrated to 2.7.1.
>>>       
>> Xalan doesn't know about tags, it knows about element nodes. I don't
>> think   elements are treated specially.
>>
>>     
>>> Please suggest.
>>>       
>> I think I've already suggested a solution. Does it not work?
>>
>> Michael Ludwig
>>
>>
>>     
>
>   


Re: XSL:VALUE-OF

Posted by mahati <rm...@gmail.com>.
Following is a param to a template

<xsl:with-param name="value">&lt;a id="frameLoader"
href="javascript:void(0);" onclick="javascript:<xsl:value-of
select="$gridName"/>.expandAllTreeRows(this);"&gt;+&lt;/a&gt;</xsl:with-param>

Then, within the template, i have:

<xsl:copy-of select="$value"/>

This makes template to print:

javascript:void(0); + 

But, the problem is that browser just prints this as raw text instead of
interpreting as href element.

You can observe that entire output is being captured correctly but gets
printed as raw text instead of being treated as html.

thanks,
mahati.


Michael Ludwig-4 wrote:
> 
> mahati schrieb:
> 
>> I tried using xsl:copy-of, but it's printing html as raw text to the
>> browser
> 
> That doesn't make sense. <xsl:copy-of select="$rtf"/> should copy the
> RTF to the output. Could you post an example?
> 
>> Requirement here is to build a href dynamically and show it. Do you
>> mean 'a' tag  is ignored by Xalan 2.7.1, by the way, this problem is
>> showing up only after we migrated to 2.7.1.
> 
> Xalan doesn't know about tags, it knows about element nodes. I don't
> think   elements are treated specially.
> 
>> Please suggest.
> 
> I think I've already suggested a solution. Does it not work?
> 
> Michael Ludwig
> 
> 

-- 
View this message in context: http://www.nabble.com/XSL%3AVALUE-OF-tp24368424p24370380.html
Sent from the Xalan - J - Users mailing list archive at Nabble.com.


Re: XSL:VALUE-OF

Posted by Michael Ludwig <ml...@as-guides.com>.
mahati schrieb:

> I tried using xsl:copy-of, but it's printing html as raw text to the
> browser

That doesn't make sense. <xsl:copy-of select="$rtf"/> should copy the
RTF to the output. Could you post an example?

> Requirement here is to build a href dynamically and show it. Do you
> mean 'a' tag  is ignored by Xalan 2.7.1, by the way, this problem is
> showing up only after we migrated to 2.7.1.

Xalan doesn't know about tags, it knows about element nodes. I don't
think <a> elements are treated specially.

> Please suggest.

I think I've already suggested a solution. Does it not work?

Michael Ludwig

Re: XSL:VALUE-OF

Posted by mahati <rm...@gmail.com>.
Thanks Michael. Yes, a tags are shown in the text, but posted text doesn't
have them.

I found that + is getting printed due to a separate piece of code within the
template, not due to 'value' parameter.

I tried using xsl:copy-of, but it's printing html as raw text to the
browser, same as my original problem that i posted in the first post on this
thread.

Requirement here is to build a href dynamically and show it. Do you mean 'a'
tag  is ignored by Xalan 2.7.1, by the way, this problem is showing up only
after we migrated to 2.7.1.

Please suggest.


Michael Ludwig-4 wrote:
> 
> mahati schrieb:
>> i could see that only + gets printed but not href tag around it.
> 
> Typically, that means you're using <xsl:value-of> instead of
> <xsl:copy-of>. In your case, the reason seems to be different.
> 
>> <xsl:call-template name=columnHeader">
>> <xsl:with-param name="value">
>> 				
>> 	<xsl:attribute name="id">frameloader</xsl:attribute>
>> 	<xsl:attribute name="href">javascript:void(0);</xsl:attribute>
>> 	<xsl:attribute name="onclick">javascript:<xsl:value-of
>> select="$gridName"/>.expandAllTreeRows(this);</xsl:attribute>
>>    				+
>> </xsl:with-param>
>> </xsl:template>
> 
> This differs from your original example. You're missing the   element.
> (Maybe it got eaten in the mail processing chain.) Xalan-J 2.7.1 and
> LibXSLT 1.1.24 both ignore this attribute. Saxon 6.5 issues a warning:
> 
>    Cannot write an attribute node when no element start tag is open
> 
> I suggest you adjust your code.
> 
> By the way, if you pass the parameter as you intend it to appear in the
> output, spare yourself the hassle of exsl:node-set() plus identity
> transform and use <xsl:copy-of> as in the following example.
> 
> In addition, use literal XML for the parameter instead of constructing
> it using <xsl:attribute>. That's much more readable. Use the latter
> method only if dynamic computation of the attribute name is required.
> 
> Michael Ludwig
> 
> <xsl:stylesheet version="1.0"
>   xmlns:exsl="http://exslt.org/common"
>   extension-element-prefixes="exsl"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 
>   <xsl:output indent="yes"/>
> 
>   <xsl:template match="/">
>    <xsl:call-template name="x">
>     <xsl:with-param name="y">
>      <eins><zwei/><drei>vier</drei></eins>
>      <!-- The following does not work: -->
>      <!-- <xsl:attribute name="z">moin</xsl:attribute> --><!-- Saxon 6.5:
>      Cannot write an attribute node when no element start tag is open -->
>     </xsl:with-param>
>    </xsl:call-template>
>   </xsl:template>
> 
>   <xsl:template name="x">
>    <xsl:param name="y"/>
>    <Urmel>
>     <good><xsl:copy-of select="$y"/></good><!-- good and simple -->
>     <hassle><!-- unnecessary hassle -->
>      <xsl:apply-templates select="exsl:node-set($y)/*"/>
>     </hassle>
>     <attr><xsl:apply-templates select="exsl:node-set($y)//@*"/></attr>
>    </Urmel>
>   </xsl:template>
> 
>   <xsl:template match="@*|node()"><!-- identity template -->
>    <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/XSL%3AVALUE-OF-tp24368424p24370188.html
Sent from the Xalan - J - Users mailing list archive at Nabble.com.


Re: XSL:VALUE-OF

Posted by Michael Ludwig <ml...@as-guides.com>.
mahati schrieb:
> i could see that only + gets printed but not href tag around it.

Typically, that means you're using <xsl:value-of> instead of
<xsl:copy-of>. In your case, the reason seems to be different.

> <xsl:call-template name=columnHeader">
> <xsl:with-param name="value">
> 				
> 	<xsl:attribute name="id">frameloader</xsl:attribute>
> 	<xsl:attribute name="href">javascript:void(0);</xsl:attribute>
> 	<xsl:attribute name="onclick">javascript:<xsl:value-of
> select="$gridName"/>.expandAllTreeRows(this);</xsl:attribute>
>    				+
> </xsl:with-param>
> </xsl:template>

This differs from your original example. You're missing the <a> element.
(Maybe it got eaten in the mail processing chain.) Xalan-J 2.7.1 and
LibXSLT 1.1.24 both ignore this attribute. Saxon 6.5 issues a warning:

   Cannot write an attribute node when no element start tag is open

I suggest you adjust your code.

By the way, if you pass the parameter as you intend it to appear in the
output, spare yourself the hassle of exsl:node-set() plus identity
transform and use <xsl:copy-of> as in the following example.

In addition, use literal XML for the parameter instead of constructing
it using <xsl:attribute>. That's much more readable. Use the latter
method only if dynamic computation of the attribute name is required.

Michael Ludwig

<xsl:stylesheet version="1.0"
  xmlns:exsl="http://exslt.org/common"
  extension-element-prefixes="exsl"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output indent="yes"/>

  <xsl:template match="/">
   <xsl:call-template name="x">
    <xsl:with-param name="y">
     <eins><zwei/><drei>vier</drei></eins>
     <!-- The following does not work: -->
     <!-- <xsl:attribute name="z">moin</xsl:attribute> --><!-- Saxon 6.5:
     Cannot write an attribute node when no element start tag is open -->
    </xsl:with-param>
   </xsl:call-template>
  </xsl:template>

  <xsl:template name="x">
   <xsl:param name="y"/>
   <Urmel>
    <good><xsl:copy-of select="$y"/></good><!-- good and simple -->
    <hassle><!-- unnecessary hassle -->
     <xsl:apply-templates select="exsl:node-set($y)/*"/>
    </hassle>
    <attr><xsl:apply-templates select="exsl:node-set($y)//@*"/></attr>
   </Urmel>
  </xsl:template>

  <xsl:template match="@*|node()"><!-- identity template -->
   <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
  </xsl:template>

</xsl:stylesheet>


Re: XSL:VALUE-OF

Posted by mahati <rm...@gmail.com>.
Thanks Chris.

I have tried your sugesstions. Now, i could see that only + gets printed but
not href tag around it. Here's the changes i have done. '+' is supposed to
be label of the href.

<xsl:call-template name=columnHeader">
<xsl:with-param name="value">
				 
				<xsl:attribute name="id">frameloader</xsl:attribute>
				<xsl:attribute name="href">javascript:void(0);</xsl:attribute> 
				<xsl:attribute name="onclick">javascript:<xsl:value-of
select="$gridName"/>.expandAllTreeRows(this);</xsl:attribute>
   				+ 
				</xsl:with-param>
</xsl:template>

and in the template i have used,

<xsl:apply-templates select="exsl:node-set($value)" mode="identity"/>

along with 

<!-- an indentity transform scoped by a specific mode - so that it is not
accidentally run--> 
<xsl:template match="@*|node()" mode="identity"> 
<xsl:copy> 
  <xsl:apply-templates select="@*|node()"  mode="identity"/> 
</xsl:copy> 
</xsl:template>

Please suggest.


Christoffer Dam Bruun wrote:
> 
> Hi mahati,
> 
> I think you should create a resulttree fragment containing the   tag 
> instead of trying to print it as text.
> I would suggest doing something like :
> 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> version="1.0"
>                       xmlns:exsl="http://exslt.org/common">
> <xsl:call-template name=columnHeader">
> <xsl:with-param name="value">
>  
>   <xsl:attribute name="href">javascript:void(0);</xsl:attribute>
>   <xsl:attribute name="id">frameloader</xsl:attribute>
>   ...
>  
> </xsl:with-param>
> </xsl:call-template>
> 
> <xsl:template name="columnHeader">
> <xsl:param name="value"/>
>    ...
>    <!-- now print the fragment -->
>    <xsl:apply-templates select="exsl:node-set($value)" mode="identity"/>
>    ...
> </xsl:template>
> 
> <!-- an indentity transform scoped by a specific mode - so that it is 
> not accidentally run-->
> <xsl:template match="@*|node()" mode="identity">
> <xsl:copy>
>   <xsl:apply-templates select="@*|node()"  mode="identity"/>
> </xsl:copy>
> </xsl:template>
> 
> Best regards,
> Christoffer Bruun
> 
> 
> mahati skrev:
>> I have a template say, columnHeader which i am calling as below in a xsl:
>>
>> <xsl:call-template name="columnHeader">
>> <xsl:with-param name="value">&lt;a id="frameLoader"
>> href="javascript:void(0);" onclick="javascript:<xsl:value-of
>> select="$gridName"/>.expandAllTreeRows(this);"&gt;+&lt;/a&gt;</xsl:with-param>
>> </xsl:call-template>
>>
>> Inside the template apart from other stuff, i print the value using
>> xsl:value as below:
>>
>> <xsl:value-of select="$value"/>
>>
>> This code was working fine before migrating to Xalan 2.7.1. But, once i
>> moved to Xalan 2.7.1, text in the value variable is getting printed as
>> normal text, it's not being treated as html and hence not being rendered
>> as
>> a href in the browser. Instead i get something like  javascript:void(0);
>> + 
>> as plaint text.
>>
>> Please suggest.
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/XSL%3AVALUE-OF-tp24368424p24369311.html
Sent from the Xalan - J - Users mailing list archive at Nabble.com.


Re: XSL:VALUE-OF

Posted by Christoffer Dam Bruun <cd...@flyingpigs.dk>.
Hi mahati,

I think you should create a resulttree fragment containing the <a> tag 
instead of trying to print it as text.
I would suggest doing something like :


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0"
                      xmlns:exsl="http://exslt.org/common">
<xsl:call-template name=columnHeader">
<xsl:with-param name="value">
<a>
  <xsl:attribute name="href">javascript:void(0);</xsl:attribute>
  <xsl:attribute name="id">frameloader</xsl:attribute>
  ...
</a>
</xsl:with-param>
</xsl:call-template>

<xsl:template name="columnHeader">
<xsl:param name="value"/>
   ...
   <!-- now print the fragment -->
   <xsl:apply-templates select="exsl:node-set($value)" mode="identity"/>
   ...
</xsl:template>

<!-- an indentity transform scoped by a specific mode - so that it is 
not accidentally run-->
<xsl:template match="@*|node()" mode="identity">
<xsl:copy>
  <xsl:apply-templates select="@*|node()"  mode="identity"/>
</xsl:copy>
</xsl:template>

Best regards,
Christoffer Bruun


mahati skrev:
> I have a template say, columnHeader which i am calling as below in a xsl:
>
> <xsl:call-template name="columnHeader">
> <xsl:with-param name="value">&lt;a id="frameLoader"
> href="javascript:void(0);" onclick="javascript:<xsl:value-of
> select="$gridName"/>.expandAllTreeRows(this);"&gt;+&lt;/a&gt;</xsl:with-param>
> </xsl:call-template>
>
> Inside the template apart from other stuff, i print the value using
> xsl:value as below:
>
> <xsl:value-of select="$value"/>
>
> This code was working fine before migrating to Xalan 2.7.1. But, once i
> moved to Xalan 2.7.1, text in the value variable is getting printed as
> normal text, it's not being treated as html and hence not being rendered as
> a href in the browser. Instead i get something like  javascript:void(0); + 
> as plaint text.
>
> Please suggest.
>