0

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

user5711656
  • 3,310
  • 4
  • 33
  • 70
  • I made a comment on your previous question (http://stackoverflow.com/questions/42498064/why-value-of-not-working-in-xslt-in-loop) which is relevant here. XSLT can't access javascript variables, because by the time the HTML and Javascript is created the XSLT (and XML) is long gone and is not accessible. XSLT is used to generate HTML (and javascript), but it is not used in the processing of that HTML. You should really start off by trying to write the HTML you want manually, putting aside XSLT until you know exactly what you want your HTML and javascript to look like. – Tim C Feb 28 '17 at 09:01
  • could you pls answer ths Question http://stackoverflow.com/questions/42505285/how-to-change-the-tag-name-in-xslt – user5711656 Feb 28 '17 at 10:01

1 Answers1

0

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>
Vasilij Altunin
  • 754
  • 1
  • 5
  • 18