开发者

Cannot concat a XSL variable with a javascript String?

So I'm trying to pass a XSL variable to a js function and then concat it wit开发者_StackOverflow中文版h a string, but it does not work.

This is what I tried:

<msxsl:script language="JavaScript" implements-prefix="js"> 
<![CDATA[
  function printString1(str)
  {
     str2 = 'hello' + str;
     return str2;
  }
]]>
</msxsl:script>

And this is how I call the method:

<xsl:value-of select="js:printString1(s:somepath/@name)"/>

Where the name is "Jake".

In this case the output is "hello" and nothing else. Should it not be "helloJake"?

But if I try:

<msxsl:script language="JavaScript" implements-prefix="js"> 
<![CDATA[
  function printString1(str)
  {
     return str;
  }
]]>
</msxsl:script>

I get "Jake" as the output.

What am I missing here?

EDIT:

This is how the XML file looks:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="MeasDataStylesheetWithScript2.xsl"?>

<measCollecFile 
xmlns="http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="measCollec">
    <fileHeader vendorName="samplename">
</fileHeader>
</measCollecFile>

And this is how the XSL file look:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:s="http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"   
xmlns:js="urn:custom-javascript"
exclude-result-prefixes="s msxsl js">

<msxsl:script language="javascript" implements-prefix="js"> 
  <![CDATA[
      function printString1(str)
      {
         var str2 = 'hello' + str;
         return str2;
      }
  ]]>
</msxsl:script>

<xsl:template match="/">
  <html>
  <body>

    <xsl:value-of select="js:printString1(s:measCollecFile/s:fileHeader/@vendorName)"/>

  </body>
  </html>

</xsl:template>
</xsl:stylesheet>


Try set var to str2:

    <msxsl:script language="JScript" implements-prefix="js">
        <![CDATA[
  function printString1(str)
  {
 var str2 = 'hello' + str;
 return str2;
  }
]]>
    </msxsl:script>

I tried following template:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    xmlns:js="js"
>
    <xsl:output method="xml" indent="yes"/>

    <msxsl:script language="JScript" implements-prefix="js">
        <![CDATA[
  function printString1(str)
  {
 var str2 = 'hello' + str;
 return str2;
  }
]]>
    </msxsl:script>

    <xsl:template match="/">
        <xsl:value-of select="js:printString1('Jake')"/>
    </xsl:template>
</xsl:stylesheet>

Output: helloJake


EDIT

Use XPath string function, e.g.:

<xsl:value-of select="js:printString1(string(s:measCollecFile/s:fileHeader/@vendorName))"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜