2012-07-18 2 views
1

XML 노드가 있습니다.이 XML 노드는 아래와 같이 큰 XML의 일부이며 아래 첨자로 된 특정 기호를 포함합니다."미만"기호가있는 XSLT 형식 문자열

<MT N="Abstract" V="Centre-of-mass energies in the region 142&lt;W&lt;sub&gt;γp&lt;/sub&gt;&lt;293 GeV with the ZEUS detector at HERA using an integrated luminosity"/> 

난에 @V 속성 값을 포맷 할 필요가되도록, &lt; W 교체해야 상술 &lt;W에서와 같이 XSLT로 파싱 그들 사이에 하나의 공간에, 알파벳 계승되는 모든 &lt; .

이것이 가능합니까? XSLT 1.0 솔루션을 선호합니다.

답변

2

가능합니다. XSLT 2.0에서는 정규 표현식 (doddle)을 사용합니다. 이 번호/문자 재미 역할을하지만, 당신이 무엇을 요구 생산

<xsl:template match="/"> 
    <xsl:call-template name="process"> 
     <xsl:with-param name="text" select="/tutorial/MT/@V"/> 
    </xsl:call-template> 
</xsl:template> 

<xsl:template name="process"> 
    <xsl:param name="text" select="."/> 
    <xsl:variable name="modtext" select="translate($text,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')"/> 
    <xsl:variable name="pretext" select="substring-before($modtext,'&lt;a')"/>   
    <xsl:choose> 
     <xsl:when test="not($pretext)"> 
      <xsl:value-of select="$text"/> 
     </xsl:when> 
     <xsl:otherwise> 
      <xsl:variable name="endpos" select="string-length($pretext)+1"/> 
      <xsl:value-of select="concat(substring($text,1, $endpos),' ')"/> 
      <xsl:call-template name="process"> 
       <xsl:with-param name="text" 
        select="substring($text,$endpos+1)"/> 
      </xsl:call-template> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

, 그러나,이 XSLT 1.0 직접 '당신이 말한'스크립트입니다.

이 생성됩니다

Centre-of-mass energies in the region 142&lt; W&lt; sub&gt;γp&lt;/sub&gt;&lt;293 GeV with the ZEUS detector at HERA using an integrated luminosity 

을 분명히 당신이 함께 번역/업데이트 및 1234567890가 처리 할 숫자를 너무 슬래시합니다.

+0

감사합니다. 원하는대로 작동합니다. * 나는 내 짐작으로는 꽤 안전하다. – itsbalur

+1

'*'는 때로는 안전 할 수 있지만 버그를 키우는 이유는 무엇입니까? 결정된. –

0

쉬운 XSLT 2.0 :

replace(@V, '(&lt;)(\p{L})', '$1 $2') 

는 더 힘들어 XSLT 1.0, 충분히 열심히 그것을 시도 할 시간이 없다고.

+0

입력 해 주셔서 감사합니다. 조만간 XSLT 2.0을 채택 할 것이므로이 방법이 유용 할 것입니다. – itsbalur