0
混在要素を含む要素の文字列を置き換えようとしていますが、XSLT初心者の方にはわかりません。 XSLT 1.0を使用する必要があり、XSLT 1.0では、混在要素を含む要素の値で文字列を置き換えることが可能かどうかはわかりません。実際のxmlファイルとxsltファイルは投稿するには大きすぎるので、私は何を達成しようとしているのかいくつかの例を考え出しました。ここでXSLT 1.0:混在したコンテンツを検索して置換する
は、私が変換しようとしている例のXMLファイルです:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml" >
<xsl:template name="find-and-replace">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="find-and-replace">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="testing">
<xsl:element name="testing">
<xsl:call-template name="find-and-replace">
<xsl:with-param name="text" select="."/>
<xsl:with-param name="replace" select="'STATUS'"/>
<xsl:with-param name="with" select="'LIVING'"/>
</xsl:call-template>
</xsl:element>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
変形例のxmlファイルは次のようになります:
ここ<?xml version="1.0"?>
<test>
<testing>The author named "<sub name="bob"/>" who wrote
<book name="Over the river" /> is STATUS.
</testing>
</test>
は私の例のXSLTファイルであります
<?xml version="1.0"?>
<test>
<testing>The author named "" who wrote is LIVING.
</testing>
</test>
select="."
として意味があります。sub
またはbook
通常のテキストのようなノード。変換されたサンプルXMLファイルは次のようになります:
<?xml version="1.0"?>
<test>
<testing>The author named "<sub name="bob"/>" who wrote <book name="Over the river" /> is LIVING.
</testing>
</test>
これはXSLT 1.0でも可能ですか?もしそうなら、私はこれをどのように達成できますか?
ご理解いただきありがとうございます。
に変更
!ありがとう! – User12