XSL/XSLT (558レス)
前次1-
抽出解除 レス栞

484
(1): 2006/08/26(土)03:28 ID:??? AAS
すみません、文字列の一括置換は XSL でどうやったら良いんでしょうか。
XML から JavaScript の文字列リテラルに変換するときにエスケープする必要があるのですが。

<foo>say "good morning"</foo>
 ↓
var msg = "say \"good morning\"";
509: 2007/04/05(木)19:40 ID:??? AAS
力いっぱい亀レスしてみる。

>>484
<xsl:template match="foo">
<xsl:text>var msg = "</xsl:text>
<xsl:call-template name="escape">
<xsl:with-param name="str" select="."/>
</xsl:call-template>
<xsl:text>";</xsl:text>
</xsl:template>

<xsl:template name="escape">
<xsl:param name="str"/>
<xsl:if test="string-length($str) != 0">
<xsl:variable name="char" select="substring($str,1,1)"/>
<xsl:choose>
<xsl:when test="$char = '\'">\\</xsl:when>
<xsl:when test="$char = '&quot;'">\"</xsl:when>
<xsl:when test="$char = '&#10;'">\n</xsl:when>
<xsl:when test="$char = '&#9;'">\t</xsl:when>
<xsl:otherwise><xsl:value-of select="$char"/></xsl:otherwise>
</xsl:choose>
<xsl:call-template name="escape">
<xsl:with-param name="str" select="substring($str,2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
前次1-
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.025s