0

In XSLT, I have to assign some values to particular element and it should get print using Javascript. For example 123 is my input element data and I want to output in such a way that the element should display "123 3456" using Javascript code in XSLT.(I am using XSLT 1.0).

It will be a great help if someone can resolve this.

dda
  • 6,030
  • 2
  • 25
  • 34
  • 1
    Please add a code example to make more clear, what you want to accomplish. Are you outputting HTML and want to insert JavaScript code? Do you want to display certain contents at a specific time or condition such as a click using JavaScript? How does your input, current transformation and desired output look like? – hielsnoppe Jan 30 '13 at 08:29

1 Answers1

0

Use a combination of the jQuery constructor and the attribute value template syntax:

<!--XSLT assignment -->
<xsl:variable name="foo" select="'123'"/>

<!--Hidden input DOM reference-->
<input id="foo" type="hidden" value="{$foo} 3456"/>

<!--JavaScript output via jQuery constructor-->
<script>
<![CDATA[
$("<span/>",{"html":$("#foo").val()}).appendTo("body");
]]>
</script>

Modern Alternative:

<!--JavaScript output via HTML5 data- attributes-->
<script data-foo="{$foo} 3456" class="xslt">
<![CDATA[
$("<span/>",{"html":$("script.xslt").attr("data-foo")}).appendTo("body");
]]>
</script>
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265