user5711656 user5711656 -4 years ago 153
jQuery Question

how to access variable in xslt?

could you please tell me how to access variable in xslt ? .I make variable in

js
.I want to print it's value .So I assign the variable value in xsl:variable
when I try to print variable value it gives me
string
instead of evaluating
here is my code
http://xsltransform.net/pPJ8LWb

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

<xsl:template match="/">
<hmtl>
<head>
<title>New Version!</title>
</head>
<script>
console.log('starte');
var start = 5;
'<xsl:variable name="start">{start}</xsl:variable>'
console.log('<xsl:value-of select="$start"/>')

</script>
</hmtl>
</xsl:template>


</xsl:transform>


Expected output :: 5
any update

Answer Source

Well, i can suggest you do like this:

demo - https://jsfiddle.net/skyr9999/behf2h7t/

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

    <xsl:template match="/">
      <hmtl>
        <head>
          <title>New Version!</title>
        </head>
        <script>
             console.log('starte');
             var start = 5; 
             document.write('<xsl:variable name="start">'+start+'</xsl:variable>');
            console.log("<xsl:value-of select='"+start+"'/>")

        </script>
      </hmtl>
    </xsl:template>


</xsl:transform>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download