下面是我的输入xml,我想基于supp-part-number生成输出。当前如果supp-part-num是重复的,那么它不会生成单独的块。我在下面提到的是当前输出和预期的输出格式。
输入xml:
<array-list total="4">
<catalog-publish-vO rec-no="1">
<short-desc>NLCTVBL Cable Clips - Round Cable 5-7mm Black</short-desc>
<err-msg>2</err-msg>
<supp-part-num>1101</supp-part-num>
</catalog-publish-vO>
<catalog-publish-vO rec-no="0">
<short-desc>NLCTVBL Cable Clips - Round Cable 5-7mm Black - 1050151244 (100 Pack)</short-desc>
<err-msg>2</err-msg>
<supp-part-num>1101</supp-part-num>
</catalog-publish-vO>
<catalog-publish-vO rec-no="1">
<short-desc>NLCTVBL Cable Clips - Round Cable 5-7mm Black</short-desc>
<err-msg>2</err-msg>
<supp-part-num>1101</supp-part-num>
</catalog-publish-vO>
<catalog-publish-vO rec-no="0">
<short-desc>NLCTVBL Cable Clips - Round Cable 5-7mm Black - 1050151244 (100 Pack)</short-desc>
<err-msg>2</err-msg>
<supp-part-num>1101</supp-part-num>
</catalog-publish-vO>
</array-list>
当前输出:
<array-list exceeds="" total="4">
<catalog-publish-vO>
<part>part_1101</part>
<pendingItem>
<description>
Description :
NLCTVBL Cable Clips - Round Cable 5-7mm Black</description>
</pendingItem>
<approvedItem>
<description>
Description :
NLCTVBL Cable Clips - Round Cable 5-7mm Black - 1050151244 (100 Pack)</description>
</approvedItem>
<pendingItem>
<description>
Description :
NLCTVBL Cable Clips - Round Cable 5-7mm Black</description>
</pendingItem>
<approvedItem>
<description>
Description :
NLCTVBL Cable Clips - Round Cable 5-7mm Black - 1050151244 (100 Pack)</description>
</approvedItem>
</catalog-publish-vO>
</array-list>
预期的输出格式:
<array-list exceeds="" total="4">
<catalog-publish-vO>
<part>part_1101</part>
<pendingItem>
<description>
Description :
NLCTVBL Cable Clips - Round Cable 5-7mm Black</description>
</pendingItem>
<approvedItem>
<description>
Description :
NLCTVBL Cable Clips - Round Cable 5-7mm Black - 1050151244 (100 Pack)</description>
</approvedItem>
</catalog-publish-vO>
<catalog-publish-vO>
<pendingItem>
<description>
Description :
NLCTVBL Cable Clips - Round Cable 5-7mm Black</description>
</pendingItem>
<approvedItem>
<description>
Description :
NLCTVBL Cable Clips - Round Cable 5-7mm Black - 1050151244 (100 Pack)</description>
</approvedItem>
</catalog-publish-vO>
</array-list>
这是我的XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="kTXLifeRequest" match="catalog-publish-vO" use="supp-part-num/text()"/>
<xsl:key name="kTXLifeRequest1" match="catalog-publish-vO" use="concat(supp-part-num,'#',@rec-no)"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:copy>
<xsl:for-each select=
"catalog-publish-vO[generate-id() = generate-id(key('kTXLifeRequest',supp-part-num)[1])]" >
<xsl:value-of select="'TEst For Loop: '"/>
<xsl:attribute name="exceeds">
<xsl:value-of select="//array-list/@exceeds" />
</xsl:attribute>
<xsl:if test="//array-list/@exceeds='Y'">
<xsl:attribute name="message">
<xsl:value-of select="'There are too many matching items to display fully. Only the first 2000 matching items are available for viewing.'" />
</xsl:attribute>
</xsl:if>
<xsl:attribute name="total">
<xsl:value-of select="//array-list/@total" />
</xsl:attribute>
<xsl:if test="err-msg = '2'">
<xsl:copy>
<xsl:variable name="group" select="key('kTXLifeRequest',supp-part-num)" />
<xsl:for-each select= "$group" >
<xsl:value-of select="'current position:'"/><xsl:value-of select="position()"/>
<xsl:if test="position() = 1">
<part>
<xsl:value-of select="concat('part_',supp-part-num)" />
</part>
</xsl:if>
<xsl:if test="@rec-no = '0'">
<approvedItem>
<xsl:choose>
<xsl:when test="err-msg != '0'">
<xsl:call-template name="CatalogDetails"></xsl:call-template>
</xsl:when>
<xsl:otherwise>
<supplier-part-number>
<xsl:value-of select="concat('part_',supp-part-num)" />
</supplier-part-number>
</xsl:otherwise>
</xsl:choose>
</approvedItem>
</xsl:if>
<xsl:if test="@rec-no = '1'">
<pendingItem>
<xsl:choose>
<xsl:when test="err-msg != '1'">
<xsl:call-template name="CatalogDetails"></xsl:call-template>
</xsl:when>
<xsl:otherwise>
<supplier-part-number>
<xsl:value-of select="concat('part_',supp-part-num)" />
</supplier-part-number>
</xsl:otherwise>
</xsl:choose>
</pendingItem>
</xsl:if>
</xsl:for-each>
</xsl:copy>
</xsl:if>
</xsl:for-each>
<xsl:for-each select=
"catalog-publish-vO[generate-id() = generate-id(key('kTXLifeRequest1',concat(supp-part-num,'#',@rec-no))[1])]" >
<xsl:variable name="group"
select="key('kTXLifeRequest1',concat(current()/supp-part-num,'#',current()/@rec-no))" />
<xsl:for-each select= "$group" >
<xsl:if test="err-msg != '2'">
<xsl:copy>
<xsl:if test="@rec-no = '0'">
<xsl:choose>
<xsl:when test="err-msg = '0'">
<part>
<xsl:value-of select="concat('part_',supp-part-num)" />
</part>
<approvedItem>
<supplier-part-number>
<xsl:value-of select="concat('part_',supp-part-num)" />
</supplier-part-number>
</approvedItem>
</xsl:when>
</xsl:choose>
</xsl:if>
<xsl:if test="@rec-no = '1'">
<xsl:choose>
<xsl:when test="err-msg = '1'">
<part>
<xsl:value-of select="concat('part_',supp-part-num)" />
</part>
<pendingItem>
<supplier-part-number>
<xsl:value-of select="concat('part_',supp-part-num)" />
</supplier-part-number>
</pendingItem>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:copy>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template name="unspsc-description">
<xsl:param name="unspsc"/>
<xsl:choose>
<xsl:when test="string-length(substring-after($unspsc,'|')) > 0">
<td title="{substring-after($unspsc,'|')}">
<xsl:value-of select="substring-before($unspsc,'|')"/>
</td>
</xsl:when>
<xsl:otherwise>
<td>
<xsl:value-of select="substring-before($unspsc,'|')"/>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="CatalogDetails">
<xsl:variable name="partNum" select="supp-part-num" />
<xsl:variable name="recNum" select="@rec-no" />
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/unspsc-code != unspsc-code" >
<unspsc-code>
UNSPSC Code :
<xsl:value-of select="unspsc-code" />
</unspsc-code>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/short-desc != short-desc" >
<description>
Description :
<xsl:value-of select="short-desc" />
</description>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/UOM != UOM" >
<UOM>
UOM :
<xsl:value-of select="UOM" />
</UOM>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/unit-price != unit-price" >
<currency-code>
<xsl:choose>
<xsl:when test="contains(unit-price,'.')">
Unit Price :
<xsl:value-of select="format-number(unit-price,'##,###,##0.00####')" />
</xsl:when>
<xsl:otherwise>
Unit Price :
<xsl:value-of select="format-number(unit-price,'##,###,##0.00')" />
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="currency-code" />
</currency-code>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/supplier-name != supplier-name" >
<supplier-name>
Supplier Name :
<xsl:value-of select="supplier-name" />
</supplier-name>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/manufacturer-name != manufacturer-name" >
<manufacturer-name>
Manufacturer Name :
<xsl:value-of select="manufacturer-name" />
</manufacturer-name>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/manf-part-num != manf-part-num" >
<manf-part-num>
Manufacturer Part Number :
<xsl:value-of select="manf-part-num" />
</manf-part-num>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/tech-specs != tech-specs" >
<tech-specs>
Technical Specification :
<xsl:value-of select="tech-specs" />
</tech-specs>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/min-order-qty != min-order-qty" >
<min-order-qty>
Min Order Qty :
<xsl:value-of select="min-order-qty" />
</min-order-qty>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/max-order-qty != max-order-qty" >
<max-order-qty>
Max Order Qty :
<xsl:value-of select="max-order-qty" />
</max-order-qty>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/lot-size != lot-size" >
<lot-size>
Pack Size :
<xsl:value-of select="lot-size" />
</lot-size>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/omni-class != omni-class" >
<omni-class>
Omni Class :
<xsl:value-of select="omni-class" />
</omni-class>
</xsl:if>
<xsl:if test="//catalog-publish-vO[supp-part-num = $partNum and @rec-no != $recNum ]/additional-details != additional-details" >
<xsl:variable name="additionalDetails">
<xsl:for-each select="additional-details/item">
<xsl:call-template name="LoopNodes">
<xsl:with-param name="tCount" select="count(.)"/>
<xsl:with-param name="var" select="'1'"/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="additional-details/item">
<xsl:attribute name="title">
Additional Details :
<xsl:value-of select="$additionalDetails" />
</xsl:attribute>
<xsl:value-of select="." /> |
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template name="LoopNodes">
<xsl:param name="tCount" />
<xsl:param name="var"/>
<xsl:choose>
<xsl:when test="$var < $tCount">
<xsl:value-of select="."/> |
<xsl:call-template name="LoopNodes">
<xsl:with-param name="tCount" select="$tCount"/>
<xsl:with-param name="var">
<xsl:number value="number($var)+1"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/> |
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>