0
中進行動態布爾檢查從我的根模板獲得唯一的賬戶值,調用去trans模板得到了輸入xml我將有多個節點,我的要求是一旦調用從root模板轉到trans模板中,如果在多個元素之間找到accountId的匹配項,則只會調用一次帳戶詳細信息模板,而不考慮其他找到的匹配項。我需要針對以上要求的解決方案。如何在xslt
輸入樣本:
<elements><accountId>1</accountId></elements>
<elements><accountId>1</accountId></elements>
<elements><accountId>2</accountId></elements>
<elements><accountId>2</accountId></elements>
<elements><accountId>3</accountId></elements>
下面的行應該在一些代碼,所以它只能調用一次被包裹
<xsl:call-template name="Account_details" />
下面是我對XSL完整的代碼
<xsl:template match="/">
<xsl:variable name="unique-accounts" select="//*/*/*/accountId/text()[generate-id()=generate-id(key('account-by-id', .)[1])]"/>
<xsl:for-each select="$unique-accounts">
<xsl:variable name="currentValue" select="current()"/>
<xsl:apply-templates select="//trans">
<xsl:with-param name="passCurrentValue" select="$currentValue"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<xsl:template match="trans">
<xsl:param name="passCurrentValue" />
<xsl:variable name="booleanValue" select="true()"/>
<xsl:for-each select="elements">
<xsl:if test="$passCurrentValue=/*/*/accountId">
<xsl:if test="$booleanValue">
<xsl:call-template name="Account_details" />
<xsl:variable name="booleanValue" select="false()"></xsl:variable>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="Account_details">
.............
</xsl:template>
如果您使用的是XSLT 1.0,那麼XSLT 1.0不支持在賦值後更改變量值 – Saurav 2015-02-09 12:25:40
哦......是否有任何方法可以檢查代碼片段是否正在第一次執行......比如添加計數器或東西 – Brittas 2015-02-09 12:29:02
@Brittas爲什麼不告訴我們你想要在這裏學習什麼的大局 - 而不是關注那些不起作用(並且不能在XSLT中工作)的微代碼? – 2015-02-09 12:32:24