Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 27th, 2008, 07:43 AM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get Ascii code for a character in XSLT

Hi,

I want the Ascii code for a specified character in xslt.
Is there a way that I can do this?

I want to even try with Javascript. But is there a way that I can set Javascript function return value to xslt variable?

Thanks in Advance,
mswin
Reply With Quote
  #2 (permalink)  
Old November 27th, 2008, 07:47 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

With XSLT 2.0 you can use http://www.w3.org/TR/xpath-functions...-to-codepoints
With XSLT 1.0 you need an extension function. How you do that depends on the XSLT processor you want to use.

--
  Martin Honnen
  Microsoft MVP - XML
Reply With Quote
  #3 (permalink)  
Old November 27th, 2008, 08:31 AM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I am using XSLT 1.0.
This is what I am using in xslt.
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"

I want to use this for one of the microsoft sharepoint webpart xslt.

Regards,
mswin
Reply With Quote
  #4 (permalink)  
Old November 27th, 2008, 08:36 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I don't know which XSLT processor Microsoft Sharepoint uses. If it is MSXML then you can write extension functions with JScript or VBScript, if it is .NET then you can write extension functions with C# or VB.NET.

--
  Martin Honnen
  Microsoft MVP - XML
Reply With Quote
  #5 (permalink)  
Old November 27th, 2008, 09:05 AM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I want to go with javascript.
Can you provide me with some sample on how to write that function in with javascript and use in xslt.

Already I had the function which get ascii code, but not able to use that in xslt.

Many thanks.
Reply With Quote
  #6 (permalink)  
Old November 27th, 2008, 09:07 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Here is an example showing how you could implement an extension function with C# for the Microsoft .NET System.Xml.Xsl.XslCompiledTransform processor:
Code:
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:my="http://example.com/2008/my"
  exclude-result-prefixes="msxsl my">

  <xsl:output method="xml" indent="yes"/>

  <msxsl:script implements-prefix="my" language="C#">
    public XPathNodeIterator stringToCodepoints(string str)
    {
      XmlDocument doc = new XmlDocument();
      using (XmlWriter writer = doc.CreateNavigator().AppendChild())
      {
        writer.WriteStartElement("characters");
        foreach (char c in str)
        {
          writer.WriteElementString("char", string.Format("{0}", (int)c));
        }
        writer.WriteEndElement();
      }
      return doc.CreateNavigator().Select("characters/char");
    }
  </msxsl:script>

  <xsl:template match="/">
    <example>
      <xsl:for-each select="my:stringToCodepoints('abcd')">
        <codepoint>
          <xsl:value-of select="."/>
        </codepoint>
      </xsl:for-each>
    </example>
  </xsl:template>
</xsl:stylesheet>
The extension function takes a string argument and returns an XPath node-set of 'char' elements, each containing the Unicode codepoint (for characters in the basic multilingual plane).

Test whether that works with your XSLT processor, if not then we have to try a different way.

--
  Martin Honnen
  Microsoft MVP - XML
Reply With Quote
  #7 (permalink)  
Old November 28th, 2008, 12:57 AM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I am getting the below error when I add thie above code to the xslt.
Security settings do not allow the execution of script code within this style sheet.

Can I have Javascript within <msxsl:script> blocks.
Any sample code on using javascript.

Thanks
-mswin
Reply With Quote
  #8 (permalink)  
Old November 28th, 2008, 04:08 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You really need to learn to do a bit of your own research. Googling for "xslt Security settings execution script code style sheet" brought back a number of relevant results in the first half-a-dozen. You need to allow scripts. This varies on which processor you use. In MSXML COM you need to see http://msdn.microsoft.com/en-us/library/ms763800(VS.85).aspx. For XsltCompiledTransform see http://msdn.microsoft.com/en-us/library/ms172415(VS.80).aspx

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #9 (permalink)  
Old November 28th, 2008, 08:21 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Quote:
quote:Originally posted by mswin


I am getting the below error when I add thie above code to the xslt.
Security settings do not allow the execution of script code within this style sheet.

Can I have Javascript within <msxsl:script> blocks.
Any sample code on using javascript.
If you get a meaningful error message then I think you use .NET's XSLT processor in your code. You will need to find a way to change the security settings if you want to use msxsl:script.

As for your request about JavaScript, JScript.NET exists but in my view it is a dead language so I am not going to bother trying to write anything in JScript.NET. The change of security settings would be required for JScript.NET as well so you would not gain anything by moving from C# to JScript.NET.

--
  Martin Honnen
  Microsoft MVP - XML
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get UNICODE or ASCII Value of a character Eyob_the_pro C# 0 January 10th, 2007 03:42 AM
Converting an ASCII character to binary? skyraider Visual Basic 2005 Basics 0 May 7th, 2006 08:20 PM
ascii code in my XSLT bluetorch XSLT 1 October 28th, 2005 01:23 PM
About the Ascii code LTGarrisonUSA C# 3 September 7th, 2004 09:39 PM
URGENT byte associated with the ASCII code shine Javascript How-To 0 July 5th, 2004 09:41 AM



All times are GMT -4. The time now is 06:34 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.