 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 27th, 2008, 07:43 AM
|
|
Registered User
|
|
Join Date: Nov 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 27th, 2008, 07:47 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

November 27th, 2008, 08:31 AM
|
|
Registered User
|
|
Join Date: Nov 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 27th, 2008, 08:36 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

November 27th, 2008, 09:05 AM
|
|
Registered User
|
|
Join Date: Nov 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

November 27th, 2008, 09:07 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

November 28th, 2008, 12:57 AM
|
|
Registered User
|
|
Join Date: Nov 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 28th, 2008, 04:08 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

November 28th, 2008, 08:21 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|
 |