[英]xsl select node with child value and pass it as parameter
我在訪問所需節點時遇到一些問題。
這是我的簡化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">
在select="component[place = '$nextPlace']
您需要select="component[place = $nextPlace]
才能正確引用變量。 但是作為for-each
處理component
元素,我看不到<xsl:with-param name="component" select='component'/>
在示例XML中選擇任何內容。 模板匹配,for-each和call模板的整體組合似乎值得懷疑,您可能想向我們展示您對輸入樣本擁有的結果,然后我們希望提出一種更簡潔,更輕松的XSLT方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.