how to access variable in xslt?

你说的曾经没有我的故事 提交于 2020-01-06 18:37:21

问题


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:


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>


来源:https://stackoverflow.com/questions/42499903/how-to-access-variable-in-xslt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!