XSLT字符串解析
以下是'PrimarySubject'的XSLT新增功能我需要将'&'字符替换为%26以及包含它的%20的字符。XSLT字符串解析
<xsl:template name="BuildLink">
<xsl:param name="PrimarySubject" />
<xsl:text>?PrimarySubject=</xsl:text>
<xsl:value-of select="$PrimarySubject" />
</xsl:template>
是否有字符串替换函数我可以在xslt版本1中使用? 谢谢,
这可以很容易地使用FXSL Library,多的电子来完成xactly其str-map
模板。
这里是一个简单的例子。
这种转变:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:testmap="testmap"
exclude-result-prefixes="xsl testmap"
>
<xsl:import href="str-map.xsl"/>
<!-- to be applied on any xml source -->
<testmap:testmap/>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="vTestMap" select="document('')/*/testmap:*[1]"/>
<xsl:call-template name="str-map">
<xsl:with-param name="pFun" select="$vTestMap"/>
<xsl:with-param name="pStr" select="'abc&d f'"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="testmap:*">
<xsl:param name="arg1"/>
<xsl:choose>
<xsl:when test="$arg1 = '&'">%26</xsl:when>
<xsl:when test="$arg1 = ' '">%20</xsl:when>
<xsl:otherwise><xsl:value-of select="$arg1"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
当任何XML文档(未使用)应用时产生通缉的结果:
abc%26d%20f
更好地使用其他人编写的库,在“我没有想到这种情况”中省了点时间。 – Nat 2010-03-12 06:16:08
@Nat,当然,FXSL的用户很少(如果有的话)需要自己实现递归。 – 2010-03-12 13:39:28
不错的文章+1 [15个字符] – 2010-03-12 13:46:15
啊,我看,你试试我的建议,在XSLT中实现URI编码器;-) – Boldewyn 2010-03-11 15:33:23