Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

urlencode - XSLT version 1 URL encoding

Is there a URL encoding function in XSLT version 1? I need something similar to encodeURIComponent function in javascript?

Seeing as this is not possible as I'm using .NET platform as the XSLT is applied to a Sharepoint page. Is there a way to code this buy calling the javascript encode function within the XML, snippet below:

<xsl:template name="BuildLink">
    <xsl:param name="PrimarySubject" />
    <xsl:text>?PrimarySubject=</xsl:text>
    <xsl:value-of select="$PrimarySubject" />
</xsl:template>

Thanks,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can use JScript embedded in XSLT ...

<msxsl:script language="JScript" implements-prefix="custom">
function uriencode(string) {
 return encodeURIComponent(string);
}
</msxsl:script>

and call it like custom:uriencode( url_to_encode )

You will first need to define the namespace though by adding to the <xsl:stylesheet ... tag the xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:custom="http://youdomain.ext/custom"

[update]

the Url i put for the custom namespace could be anything .. it is just a unique identifier..
(the link concludes that it is less confusing if you do not use a url as the identifier..)

[udpdate 2]

Some added info.
If you use MSXML6 then you need to manually allow scripting in the XSLT, by using the AllowXsltScript property.. ( reference )
Depending on the way you load the xslt and its settings have a look at the examples at Script Blocks Using msxsl:script on how to alow scripts


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...