2014-10-21 3 views
0

XSLT를 사용하여 BBCode를 HTML로 변환하려고합니다. 그게 내가 무슨 짓을했는지 :XSLT를 사용하여 BBCode를 HTML로 변환

내가 무엇을 얻을
<xsl:stylesheet exclude-result-prefixes="foo xslt" version="2.0" xmlns="http://www.w3.org/TR/xhtml1/strict" 
    xmlns:foo="urn:foo" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xslt="http://xml.apache.org/xslt"> 
    <xsl:output encoding="UTF-8" indent="yes" media-type="text/html" method="html" version="4.0" xslt:indent-amount="4"/> 

    <xsl:function name="foo:bbcode-to-xhtml"> 
    <xsl:param name="bbcode"/> 
    <xsl:analyze-string flags="is" regex="\[url=(.*?)\](.*?)\[/url\]" select="$bbcode"> 
     <xsl:matching-substring> 
     <a href="{regex-group(1)}"> 
      <xsl:value-of select="regex-group(2)"/> 
     </a> 
     </xsl:matching-substring> 
     <xsl:non-matching-substring> 
     <xsl:value-of select="."/> 
     </xsl:non-matching-substring> 
    </xsl:analyze-string> 
    </xsl:function> 

    <xsl:template match="/"> 
    <xsl:value-of select="foo:bbcode-to-xhtml('A [url=http://www.example.com/]Foo[/url] of Bar!')"/> 
    </xsl:template> 
</xsl:stylesheet> 

:

A Foo of Bar!

그리고 내가 기대하는 것입니다 :

A <a href="http://www.example.com/">Foo</a> of Bar!

사람이 내가 잘못 무슨 말을 할 수 있습니까?

답변

0

시도해보십시오. <xsl:copy-of select="foo:bbcode-to-xhtml('A [url=http://www.example.com/]Foo[/url] of Bar!')"/>은 평범한 텍스트 노드 만 사용합니다.

+0

그게 전부 야! 이런! ;) – Michael

관련 문제