我有一些問題需要訪問我想要的節點。xsl選擇具有子值的節點並將其作爲參數傳遞
這裏是我的簡單的xml:
<chain>
<components>
<component>
<place>2</place>
<name>bbb</name>
</component>
<component>
<place>1</place>
<name>aaa</name>
</component>
<component>
<place>3</place>
<name>ccc</name>
</component>
</components>
</chain>
輸出我想要的:
aaa is connected to bbb
bbb is connected to ccc
和我的xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes"/>
<xsl:template match="text()"/>
<xsl:template name="writeComponent">
<xsl:param name="my_component"/>
<xsl:value-of select="$my_component/name"/>
</xsl:template>
<xsl:template match="/chain/components">
<xsl:for-each select="component">
<xsl:variable name="nextPlace" select="./place + 1"/>
<xsl:call-template name="writeComponent">
<xsl:with-param name="my_component" select='component'/>
</xsl:call-template>
is connected to
<xsl:call-template name="writeComponent">
<xsl:with-param name="my_component" select="component[place = '$nextPlace']"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我需要調用twite不同相同的模板節點參數
得到任何幫助,感謝
編輯:我發現我的問題的解決方案
來電:
<xsl:call-template name="writeComponent">
<xsl:with-param name="component_param" select="."/>
</xsl:call-template>
is connected to
<xsl:call-template name="writeComponent">
<xsl:with-param name="component_param" select="/chain/components/component[place = $nextPlace]"/>
</xsl:call-template>
,並在所謂的模板,你需要循環在<xsl:for-each select="$component_param">
您能添加您的預期輸出嗎?問題不是很清楚,我認爲,當它已經在組件上循環時,只有1個呼叫模板就足夠了。 – 2014-12-02 09:59:03
我添加了所需的輸出,而我的問題是我無法通過節點作爲參數 – 2014-12-02 11:06:24
你能請求轉換背後的**邏輯**?我沒有看到'aaa是如何連接到bbb'的,除了兩個是兄弟姐妹(但爲什麼不是'aaa連接到ccc'?)。 – 2014-12-02 12:11:39