1
我使用XSLT解析.xsd文件。我的問題是,我只能 寫入輸出數據,因爲我在當前節點中發現它正在使用 。XSLT如何將數據傳遞給父節點
有什麼辦法可以將一些數據從節點發送到祖先節點?
一個簡單的例子,我得到和我想要的。
- 我當前的代碼: -
<xsl:template match="complexType">
<xsl:text>struct </xsl:text>
<xsl:text>T_</xsl:text>
<xsl:value-of select"current/@name"/>
<xsl:text>{</xsl:text>
<xsl:text>
</xsl:text>
<xsl:apply-templates select="sequence"/>
<xsl:text>};</xsl:text>
</xsl:template>
<xsl:template match="sequence">
<xsl:apply-templates select="element"/>
</xsl:template>
<xsl:template match="element">
<xsl:value-of select"current/@type"/>
<xsl:text> </xsl:text>
<xsl:value-of select"current/@name"/>
</xsl:template>
- 我的源文件 -
<complexType name="cp_name">
<sequence>
<element name="el_name" type="int" minOccurs="1" maxOccurs="1">
</element>
</sequence>
</complexType>
- 我的電流輸出: -
struct T_cp_name
{
int el_name;
};
- 所需輸出 -
<!-- // First, use some data from the inner node (element) -->
typedef int Type_in_element;
<!-- // Then, use a combination of data from both the inner and the -->
<!-- // ancestor node (complexType) -->
struct T_cp_name
{
Type_in_element el_name; // data from the inner node (<element>)
};
雖然你的答案解析確切的例子中,我一直在尋找 一個更通用的解決方案,其中標籤 的例子可以在任何地方存在,在任何深處 樹。 –
fer
如果它對你有用比接受答案。 – Rupesh