您可以使用XSLT來完成。然後只是用來生成你需要的代碼片段。
(記得要設置輸出格式爲純文本)
編輯:樣品XSLT腳本
輸入 - A.XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="b.xsl"?>
<set name='myVar'>
<concat>
<s>newText_</s>
<ref>otherVar</ref>
</concat>
</set>
腳本 - b.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="text" />
<xsl:template match="set">
<xsl:value-of select="@name"/>=<xsl:apply-templates/>
</xsl:template>
<xsl:template match="concat">
<xsl:for-each select="*">
<xsl:if test="position() > 1">+</xsl:if>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template match="ref">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="s">
<xsl:text>"</xsl:text>
<xsl:apply-templates/>
<xsl:text>"</xsl:text>
</xsl:template>
</xsl:stylesheet>
不是e a.xml包含一條指令,該指令將允許支持XSLT的瀏覽器使用樣式表b.xsl進行呈現。 Firefox是這樣的瀏覽器。在Firefox並打開A.XML會看到
myVar="newText_"+otherVar
注意,XSLT是一個相當有能力的編程語言,所以有很多可以做。
您可否詳細說明'功能語言功能,如循環'。你對循環的定義是什麼? – 2010-02-04 19:05:07
以下內容: myList<! - 對myList的每個元素執行一些操作 - > 。有點像JSP/EL。 –
Jon
2010-02-04 19:21:53