我正在使用XSLT。如何在不移除xslt中的內容的情況下刪除某些標記並將整個內容XML作爲輸入傳遞給另一個模板
源XML:
<?xml version="1.0" encoding="iso-8859-1"?>
<Content>
<alertHeader>
<ol xmlns="http://www.w3.org/1999/xhtml">
<li>
<strong>Review</strong>
your current available balance. It can be obtained 24 hours a day, 7 days a week through
<a href="/ALL_UNDER_123">Account Activity</a>
any 123 ATM or by calling
<a id="dynamicvariable" href="#" name="Customercare">[Customercare]</a>
at
<a id="dynamicvariable" href="#" name="contactNo">[contactNo]</a>
.
</li>
<li>
<strong>Take into consideration</strong>
<ul>
<li>Please get in touch with us</li>
<li>Please consider this as important info</li>
</ul>
</li>
<li>
<strong>Current</strong>
Statementt doesnot match the requirement
<a id="dynamicvariable" href="#" name="Actual acccount">[Actual acccount]</a>
,plus
<a id="dynamicvariable" href="#" name="totalcharges">[totalcharges]</a>
Make u r response as positive.
</li>
</ol>
<p xmlns="http://www.w3.org/1999/xhtml"></p>
<div xmlns="http://www.w3.org/1999/xshtml"></div>
<span xmlns="http://www.w3.org/1999/xshtml"></span>
</alertHeader>
</Content>
我想寫一個XSLT在標籤alertHeader傳遞全部內容作爲值到另一個模板。
我想修改這段代碼如下。
需要 1.Remove the tags <p></p>, and <div></div>,<span></span> and <a></a>. I want to remove only tags but not the value of the tags. It should be there as it is.
2.Pass the content including tags to "Process" template.
輸出:
<aaa>
<text>
<ol xmlns="http://www.w3.org/1999/xhtml">
<li>
<strong>Review</strong>
your current available balance. It can be obtained 24 hours a day, 7 days a week through
<dynamicvariable name="Customercare"/>
at
<dynamicvariable name="contactNo"/>
.
</li>
<li>
<strong>Take into consideration</strong>
<ul>
<li>Please get in touch with us</li>
<li>Please consider this as important info</li>
</ul>
</li>
<li>
<strong>Current</strong>
Statementt doesnot match the requirement
</li>
</ol>
</text>
</aaa>
當前XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="alertHeader">
<xsl:call-template name="process">
<xsl:with-param name="text" select="." />
</xsl:call-template>
</xsl:template>
<xsl:template name="process">
<xsl:param name="text" />
<xsl:variable name="head" select="substring-before($text, '[')" />
<xsl:variable name="tag" select="substring-before(substring-after($text, '['), ']')" />
<xsl:variable name="tail" select="substring-after($text, ']')" />
<xsl:choose>
<xsl:when test="$head != '' and $tag != ''">
<xsl:value-of select="$head" />
<dynamicVariable name="{$tag}" />
<!-- recursive step: process the remainder of the string -->
<xsl:call-template name="process">
<xsl:with-param name="text" select="$tail" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
任何一個可以說什麼需要我的代碼的所有變化。
謝謝。
我沒有得到的願望輸出在此。 – Patan 2012-04-25 07:54:24
不錯,你必須相應地重寫'process' – hroptatyr 2012-04-25 07:59:22
我想在輸出中獲取標籤。 – Patan 2012-04-25 08:01:56