2011-08-16 10 views
0

シンボルをHTMLコードに翻訳しようとしています。 'このコードで’へ:HTMLコード( "&something;")への翻訳方法

<xsl:variable name="apos">'</xsl:variable> 
<xsl:variable name="test">&rsquo;</xsl:variable> 

<xsl:value-of select='translate(title, $apos, $test)' /> 

これは動作します:

<xsl:variable name="test">&#39;</xsl:variable> 

しかし、それは可能である第一の例を動作させるには?

答えて

1

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

    <xsl:template match="/"> 
     <xsl:variable name="apos">'</xsl:variable> 
     <xsl:variable name="test">&amp;rsquo;</xsl:variable> 
     <xsl:variable name="input">'sfdds'</xsl:variable> 

     <xsl:variable name="result"> 
      <xsl:call-template name="replace"> 
       <xsl:with-param name="input" select="$input"/> 
       <xsl:with-param name="value" select="$apos"/> 
       <xsl:with-param name="replacement" select="$test"/> 
      </xsl:call-template> 
     </xsl:variable> 

     <xsl:value-of select="$result" disable-output-escaping="yes"/> 

    </xsl:template> 


    <xsl:template name="replace"> 
     <xsl:param name="input"/> 
     <xsl:param name="value"/> 
     <xsl:param name="replacement"/> 

     <xsl:choose> 
      <xsl:when test="contains($input, $value)"> 
       <xsl:value-of select="substring-before($input, $value)"/> 
       <xsl:value-of select="$replacement"/> 
       <xsl:call-template name="replace"> 
        <xsl:with-param name="input" select="substring-after($input, $value)"/> 
        <xsl:with-param name="value" select="$value"/> 
        <xsl:with-param name="replacement" select="$replacement"/> 
       </xsl:call-template> 
      </xsl:when> 

      <xsl:otherwise> 
       <xsl:value-of select="$input"/> 
      </xsl:otherwise> 
     </xsl:choose> 

    </xsl:template> 

</xsl:stylesheet> 

出力:

&rsquo;sfdds&rsquo; 
+0

@downvoter、Care to comment? –

+0

このようなことを試したところ、クライアントサイドのhtmlは文字通り '’' – Cruncher

3

&rsquo;はHTMLエンティティですが、XSLTは5つのエンティティしか定義されていないXMLを使用して記述されています。ウィキペディアのページ(XML/HTML entities)を参照してください。

あなたのXSLTは、以下の例を参照してください、 &rsquo;のようなものを理解することができる解析するXMLパーサように、あなたが潜在的にHTNMLエンティティを追加するDOCTYPEを使用することができ

:あなたはXSLT 1.0で再帰を使用することができます

http://www.quackit.com/xml/tutorial/xml_creating_entities.cfm

関連する問題