2010-12-20 6 views
1

MOSS07によって自動的に作成されたリンクを%20を含むスペースに変更する必要があります。%20へのリンクのXSL空間の変更


例:

{$SafeLinkURL} 

スペース

https://stackoverflow.com/example%20of%20spaces


の出力https://stackoverflow.com/example誰もがこの上でいくつかの光を当てることができた場合は、行ってくださいます。事前に

おかげで、

ニック

+0

良い質問、+1。完全なXSLT 1.0ソリューションについては私の答えを見てください。 :) –

答えて

1

この質問にを求めているまさに明確ではありません。

問題は「%20」で指定した文字列内のすべてのスペース文字を交換する場合に、ここにXSLTソリューションです:この変換は、このXML文書に適用される場合

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 

<xsl:template match="node()|@*"> 
    <xsl:copy> 
    <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="link/text()[contains(., ' ')]"> 
    <xsl:call-template name="replace"/> 
</xsl:template> 

<xsl:template name="replace"> 
    <xsl:param name="pText" select="."/> 
    <xsl:param name="pTarget" select="' '"/> 
    <xsl:param name="pReplacement" select="'%20'"/> 

    <xsl:choose> 
    <xsl:when test="not(contains($pText, $pTarget))"> 
    <xsl:value-of select="$pText"/> 
    </xsl:when> 
    <xsl:otherwise> 
    <xsl:value-of select= 
     "substring-before($pText, $pTarget)"/> 
    <xsl:value-of select="$pReplacement"/> 
    <xsl:call-template name="replace"> 
     <xsl:with-param name="pText" select= 
      "substring-after($pText, $pTarget)"/> 
     <xsl:with-param name="pTarget" select="$pTarget"/> 
     <xsl:with-param name="pReplacement" 
      select="$pReplacement"/> 
    </xsl:call-template> 
    </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 
</xsl:stylesheet> 

<link>http://stackoverflow.com/example of spaces</link> 

指名手配、正しい結果がが生成されます

<link>http://stackoverflow.com/example%20of%20spaces</link> 
+0

デコード/エンコード文字列拡張関数のトンがより適していると判断していませんか? URLが付いているものは、通常、より複雑になる傾向があります。 – Flack

+0

@Flack:確かに、彼はXSLTでこれを行う方法を尋ねているようです。私は、正確にそのようなURLエンコーディングのための標準XPath 2.0関数があると思います。 –

+0

私はポイントを持っており、あなたは正しいです。しかし、私は、EXSLTの文字列または類似のための追加のリンクは、まだ言及する価値があると思います:) – Flack

2

XSLT 2.0機能(S)Dimitrieが言及は、次のとおり

  1. fn:encode-for-uri()
  2. fn:iri-to-uri()
  3. fn:escape-html-uri()

詳細な明細書および実施例のリンクを参照してください。あなたの場合(XSLT 2.0プロセッサを使用していた可能性がある場合)、fn:iri-to-uri()はあなたの問題を解決しました。

ただし、これらの関数は現在のXSLT 1.0環境では動作しません。だから、この記事を他の人のための将来の参考資料として見てください。

関連する問題