我正在嘗試使用XSLT 2.0來替換任意數量的子字符串。假設我的XML如下所示:多字符串替換
<scheme_template id="job"
use_when_ref="action">
<![CDATA[
<p>
@[email protected] Haul is based on
<b>@[email protected]:</b>
</p>
<table class="scheme_job_table">
<tr>
<td>2 or less</td>
<td>@[email protected]</td>
</tr>
<tr>
<td>3-5</td>
<td>@[email protected]</td>
</tr>
<tr>
<td>6 or more</td>
<td>@[email protected]</td>
</tr>
</table>
]]>
</scheme_template>
<scheme name="JOB! CHICKEN SOUP FOR THE SOULLESS"
copies="1">
<use_scheme_template id_ref="job">
<property id="job.fluff">
Chose 1 of your monsters to make and sell
heart-warming books of life-affirming awwwww.
</property>
<property id="job.stat">Smart</property>
<property id="job.low">$4</property>
<property id="job.middle">$6</property>
<property id="job.high">$8</property>
</use_scheme_template>
</scheme>
我想使用XSL轉換將所有「屬性」值放入方案模板中。我的(有問題的)XSL看起來像這樣:
<xsl:template match="use_scheme_template" mode="expand_template">
<xsl:param name="template_id" select="@id_ref"/>
<xsl:param name="base_text" select="//scheme_template[@id=$template_id]"/>
<xsl:variable name="expanded_text">
<xsl:apply-templates select="property" mode="replace_props">
<xsl:with-param name="base_text" select="$base_text"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:value-of select="$expanded_text" disable-output-escaping="yes" />
</xsl:template>
<xsl:template match="property" mode="replace_props">
<xsl:param name="base_text"/>
<xsl:value-of select="replace($base_text, concat('@', @id, '@'), text())"/>
</xsl:template>
但是,這隻會替換第一個屬性。
我需要做什麼才能在同一個字符串上運行replace
任意多次?
請期望輸出XML添加到您的問題 - 我不清楚它應該是什麼樣子。謝謝! –
** 1。**請張貼能讓我們重現問題的代碼。 ** 2。**當您處理它時,考慮簡化示例以便重現問題所需的裸露元素。 ** 3。**我不認爲你想要「*在同一個字符串*上運行替換任意次數」。你可能想要對第一個結果運行第二次替換,等等 - 請參閱:http://stackoverflow.com/questions/22265164/xslt-1-0-string-replace-and-concatenation/22272894 #22272894 –