[英]<xsl:apply-templates> usage with <xsl:for-each> using XSLT1.0 transformations
[英]how to apply templates within xsl:for-each
考慮以下xml結構:
<Lists>
<PriceList Lab="50|51|03|21">
<action order="11" type="1" />
<action order="12" type="2" />
</PriceList>
<PriceList Lab="100">
<action order="13" type="3" />
<action order="14" type="4" />
</PriceList>
</Lists>
用tokenize()拆分實驗室,然后應對每個實驗室操作進行應用。 我嘗試使用for-each,然后使用選擇動作標簽。 但這是行不通的,editix說“此處不能使用Axis step child :: element(action,xs:anyType):上下文項是一個原子值”。 這是xslt。
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="action">
<xsl:value-of select="@order"/>
</xsl:template>
<xsl:template match="PriceList[@Lab]">
<xsl:for-each select="tokenize(@Lab, '\|')">
<xsl:value-of select="." />
<xsl:apply-templates select="action" />
</xsl:for-each>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
我該怎么做才能使這項工作?
您需要在for-each
之外定義一個變量:
<xsl:template match="PriceList[@Lab]">
<xsl:variable name="this" select="."/>
<xsl:for-each select="tokenize(@Lab, '\|')">
<xsl:value-of select="." />
<xsl:apply-templates select="$this/action" />
</xsl:for-each>
</xsl:template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.