我有以下模板的XSLT樣式表:XSLT模板不生產元素名稱正確
<xsl:template match="row/*">
<xsl:for-each select=".">
<saxon:assign name="count"><xsl:value-of select="$count+1" /></saxon:assign>
<xsl:variable name="node-value" as="xs:string" select="." />
<xsl:variable name="node-name" as="xs:string"><xsl:value-of select="preceding::fielddescription/name(*[$count])" /></xsl:variable>
<xsl:variable name="current-node" as="xs:string"><xsl:value-of select="preceding::fielddescription/.[$count]" /></xsl:variable>
<xsl:if test=".[not(self::F2 or self::F7)]">
<xsl:element name="{$current-node}">
<xsl:value-of select="normalize-space(.)" />
</xsl:element>
</xsl:if>
<xsl:if test=".[self::F2]">
<UPCs>
<xsl:element name="{$current-node}"><xsl:value-of select="normalize-space(.)" /></xsl:element>
</UPCs>
</xsl:if>
<xsl:if test=".[self::F7]">
<xsl:element name="{$current-node}">
<xsl:value-of select="lower-case(normalize-space(replace(., '[/ ]', '-')))" />
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:template>
我希望它做的是工藝節點集內給予這樣的每一個元素:
<fielddescription>
<F1>ExternalId</F1>
<F2>UPC</F2>
<F3>Name</F3>
<F4>Description</F4>
<F5>ProductPageUrl</F5>
<F6>ImageUrl</F6>
<F7>CategoryExternalId</F7>
</fielddescription>
,並生成新的元素,標籤名稱與<fielddescription>
中每個<row>
樣式表找到的每個元素的值相匹配。到目前爲止,除了這個模板外,我的所有樣式表都可以工作。它會持續生成具有整個序列名稱的標籤的節點:
<Product removed="false">
<ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>ED003-QCX</ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>
<UPCs>
<ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>031878025147</ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>
</UPCs>
<ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>Sealy Naturals-Cotton Crib Mattress Pad</ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>
<ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>Give baby plush comfort from natural cotton fibers with the innovative Sealy Naturals-Cotton Crib Mattress Pad.</ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>
<ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>http://www.kolcraft.com/sealy-naturals-cotton-crib-mattress-pad.html</ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>
<ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>http://www.kolcraft.com/media/catalog/product/e/d/ed003-qcx-1_1_4.jpg</ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>
<ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>bedding-pads</ExternalIdUPCNameDescriptionProductPageUrlImageUrlCategoryExternalId>
<Attributes>
<Attribute id="BV_FE_FAMILY">
<Value>ED003</Value>
</Attribute>
<Attribute id="BV_FE_EXPAND">
<Value>BV_FE_FAMILY:ED003</Value>
</Attribute>
</Attributes>
</Product>
我的模板做錯了什麼?我還應該注意到,我使用了<saxon:assign>
特性,因爲我不知道如何讓樣式表使用更新的變量來工作......我知道有一種更好的方法可以用遞歸來實現,但我不能找不到一種方法來實現它的工作。誰能幫忙?
'current-node'變量被定義爲模板開始的'for-each'組的子元素:' xsl:variable>' –