0

I am using an embedded stylesheet into xml document Referring the link. My intension is getting the filename from xml tag through XSLT and validating it with the help of Javascript. I am trying to pass an xsl variable value to a javascript function. My alert is not working. I am sure the browser runs my Javascript.

But I am getting the syntax error error image

My XML code

<?xml version="1.0" standalone="no" ?>
<?xml-stylesheet type="text/xsl" href="#id(xyz)"?>
<file>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="xyz">

<xsl:template match="/">
<xsl:variable name="fName" select="filename" />
<xsl:text><xsl:value-of select="$fName"/></xsl:text>
 <html>
    <head>
      <script type="text/javascript">

      var fileName = "<xsl:value-of select="$fName"/>"; 
      alert(fileName);
      </script>
    </head>
    <body>     

    </body>
 </html>
</xsl:template>
</xsl:stylesheet>

<filename>10052015</filename>
</file>
3
  • 1
    i think script tags are unparsed. you can simply inject the value into a hidden div or input. Commented Sep 17, 2015 at 18:07
  • Which browser gives that error message? Commented Sep 17, 2015 at 21:03
  • MartinHonnen - Internet Explorer Commented Sep 18, 2015 at 11:51

1 Answer 1

1

As far as I remember, Internet Explorer never supported referencing embedded stylesheets.

With Firefox and Chrome http://home.arcor.de/martin.honnen/xslt/test2015091801.xml works for me, its source code is

<?xml version="1.0" standalone="no" ?>
<?xml-stylesheet type="text/xsl" href="#xyz"?>
<!DOCTYPE file [
  <!ATTLIST xsl:stylesheet
     id ID #REQUIRED>
]>
<file>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="xyz" version="1.0">

<xsl:template match="/">
 <xsl:variable name="fName" select="file/filename" />
 <html>
    <head>
      <script type="text/javascript">

      var fileName = "<xsl:value-of select="$fName"/>"; 
      alert(fileName);
      </script>
    </head>
    <body>     
      <h1>Test</h1>
    </body>
 </html>
</xsl:template>
</xsl:stylesheet>

<filename>10052015</filename>
</file>
Sign up to request clarification or add additional context in comments.

1 Comment

@Matin Honnen - Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.