XML内のCData要素の下にある文字列を置き換えるにはどうすればよいですか? は、ここで私は以下のような2つの条件に合致するようにしようとしている:XML内の文字列を検索し、その終わりに1つの部分文字列が一致し、別の部分文字列を含む
<xsl:template match="@*[ends-with((local-name(),'mustEndWithThisSubstring'))] and not(contains((local-name(),'mustContainThisSubstring')))" >
1 - 「のxsl:マッチ」のための複数の条件を持つことがどのように節を?
2(不明)にマッチした文字列を希望の文字列(既知)に置き換えるには?
以下のスニペットをご覧ください。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" cdata-
section-elements=replacingWith"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*[ends-with((local-name(),'mustEndWithThisSubstring'))] and not(contains((local-name(),'mustContainThisSubstring')))" >
<xsl:copy>
<replacingWith"/>
<xsl:value-of select="substring-after(., '<foundStringThatMatchesConditions>'), '</foundStringThatMatchesConditions>')"/>
</replacingWith>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
入力:
<soap:Body>
<pre:getResponse>
<![CDATA[
<foundStringThatMatchesConditions>
.......
</foundStringThatMatchesConditions>
]]>
</pre:getResponse>
</soap:Body>
出力:
<soap:Body>
<pre:getResponse>
<![CDATA[
<replacingWith>
.......
</replacingWith>
]]>
</pre:getResponse>
</soap:Body>
[あなたの前の質問](https://stackoverflow.com/questions/44532804/move-an-xml-element-from-its-place-to-under-another-parent-element-using)から知っておくべきです。 -xslt)は、CDATAの内容が文字列関数以外のXPath式では対処できない無意味な文字列であることを示しています。これは、ターゲットが真のXMLツリーであってもXPath式があまり意味をなさないという点にあります。 –