how to access variable in xslt?

2019-09-17 17:07发布

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

1条回答
闹够了就滚
2楼-- · 2019-09-17 17:35

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>
查看更多
登录 后发表回答