2011-08-16 7 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

당신은 XSLT 1.0에서 재귀를 사용할 수 있습니다 :

<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, 관심 케어? –

+0

이렇게 해보았을 때 클라이언트 측의 html은'’' – Cruncher

3

&rsquo;은 HTML 엔티티 인 반면 XSLT는 5 개의 엔티티 만 정의 된 XML을 사용하여 작성됩니다. 위키 피 디아 페이지 (XML/HTML entities)를 참조하십시오.

당신의 XSLT는 &rsquo; 같은 것들을 이해할 수있는 구문 분석하는 XML 파서는, 다음과 같은 예를 볼 수 있도록 잠재적 HTNML 엔티티를 추가 할 DOCTYPE을 사용할 수

:

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

관련 문제