bbcode를 html로 변환 할 수있는 실행 가능한 솔루션을 찾는 데 도움이 필요합니다. 여기서는 ive가 지금까지 왔지만 bbcodes가 줄 바꿈 될 때 실패합니다.xslt 2.0으로 BBCode 구문 분석
의 Src :
[quote id="ohoh81"]asdasda
[quote id="ohoh80"]adsad
[quote id="ohoh79"]asdad[/quote]
[/quote]
[/quote]
코드 : XSLT 잘 구성된 XML이 아닌 임의의 텍스트를 처리 할 수 있도록 설계되어 있기 때문에
<xsl:variable name="rules">
<code check="
" ><br/></code>
<code check="\[(quote)(.*)\]" ><span class="quote"></code>
</xsl:variable>
<xsl:template match="text()" mode="BBCODE">
<xsl:call-template name="REPLACE_EM_ALL">
<xsl:with-param name="text" select="." />
<xsl:with-param name="pos" select="number(1)" />
</xsl:call-template>
</xsl:template>
<xsl:template name="REPLACE_EM_ALL">
<xsl:param name="text" />
<xsl:param name="pos" />
<xsl:variable name="newText" select="replace($text, ($rules/code[$pos]/@check), ($rules/code[$pos]))" />
<xsl:choose>
<xsl:when test="$rules/code[$pos +1]">
<xsl:call-template name="REPLACE_EM_ALL">
<xsl:with-param name="text" select="$newText" />
<xsl:with-param name="pos" select="$pos+1" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of disable-output-escaping="yes" select="$newText" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
구조화 된 언어를 구문 분석하기 위해 정규 표현식을 사용하지 않는 것이 일반적으로 여기 있다고 생각했습니다. ;) – Tomalak
실제로는 두 번만 일치하므로 잘 될 것입니다. Thanx again Pavel – Sveisvei
regex-group은 위의 regex를 가진 regex-group (1)이어야합니다. 생산성 btw에서 작동합니다. – Sveisvei