xsl:sort 与之前的兄弟 XSLT 1.0 XSL-FO muenchian xsl:key
xsl:sort with preceding-sibling XSLT 1.0 XSL-FO muenchian xsl:key
我想访问排序列表中的前同级。我正在使用 Antenna House 6.2 和 XSLT 1.0。我尝试将 msxsl 扩展与 node-set()
一起使用,但调用 node-set()
失败。有人说在 1.0 中无法访问排序列表中的前同级,而其他人则提到了 Muenching Grouping 和使用 xsl:key
所以我现在正在尝试。我看过这个页面:http://www.jenitennison.com/xslt/grouping/muenchian.html
table 排序正确,但我一直无法弄清楚如何使用键检索已排序列表的前同级。我需要更多钥匙吗?我在 partNumberValue
上排序,然后在 figureNumber
上排序,figureNumber
可能有一个 figureNumberVariant
。任何建议表示赞赏。
XML:
<illustratedPartsCatalog>
<figure id="fig1">...</figure>
<catalogSeqNumber assyCode="05" figureNumber="01" indenture="0" item="000" subSubSystemCode="1" subSystemCode="1" systemCode="15">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>AT</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="8910-276">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>GGACC AIR VALVE ASSEMBLY</descrForPart></itemIdentData>
</partSegment><applicabilitySegment><usableOnCodeAssy>A</usableOnCodeAssy>
</applicabilitySegment></itemSeqNumber></catalogSeqNumber>
<catalogSeqNumber assyCode="05" figureNumber="01" indenture="0" item="001" itemVariant="A" subSubSystemCode="1" subSystemCode="2" systemCode="15">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>RF</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="8910-281">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>JJACC AIR VALVE ASSEMBLY</descrForPart></itemIdentData>
</partSegment><applicabilitySegment><usableOnCodeAssy>B</usableOnCodeAssy>
</applicabilitySegment></itemSeqNumber></catalogSeqNumber>
<catalogSeqNumber assyCode="05" figureNumber="01" indenture="1" item="000" subSubSystemCode="1" subSystemCode="1" systemCode="1">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>1</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="2079-1302-1">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>NAMEPLATE COVER</descrForPart></itemIdentData>
</partSegment>
<partLocationSegment>
<attachStoreShipPart attachStoreShipPartCode="1"/></partLocationSegment>
</itemSeqNumber></catalogSeqNumber>
<figure id="fig2">...</figure>
<catalogSeqNumber assyCode="05" figureNumber="02" indenture="1" item="030" subSubSystemCode="1" subSystemCode="2" systemCode="15">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>AR</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="63358">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>LOCK WIRE</descrForPart></itemIdentData></partSegment>
</itemSeqNumber></catalogSeqNumber>
<catalogSeqNumber assyCode="05" figureNumber="02" indenture="1" item="040" subSubSystemCode="1" subSystemCode="2" systemCode="15">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>1</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="1476-3248-1">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>SHIELD</descrForPart></itemIdentData></partSegment>
</itemSeqNumber></catalogSeqNumber>
<catalogSeqNumber assyCode="05" figureNumber="02" indenture="1" item="050" subSubSystemCode="1" subSystemCode="2" systemCode="15">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>2</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="1025-129">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>SCREW</descrForPart></itemIdentData></partSegment>
<partLocationSegment>
<attachStoreShipPart attachStoreShipPartCode="1"/></partLocationSegment>
</itemSeqNumber></catalogSeqNumber>
</illustratedPartsCatalog>
XSLT:
<xsl:key name="kfigNo" match="catalogSeqNumber" use="@figureNumber" />
<xsl:template match="illustratedPartsCatalog">
<xsl:apply-templates />
<fo:table>
<fo:table-header>
<fo:table-row>
<fo:table-cell>
<fo:block>PART</fo:block>
<fo:block>NUMBER</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>FIG</fo:block>
<fo:block>NO.</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>ITEM</fo:block>
<fo:block>NO.</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>QTY.</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:call-template name="SortParts"/>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template name="SortParts">
<xsl:for-each select="catalogSeqNumber[key('kfigNo', @figureNumber)]">
<xsl:sort select="concat(itemSeqNumber/partRef/@partNumberValue, @figureNumber,@item)"/>
<xsl:call-template name="catalogSeqNumber-NI">
<xsl:with-param name="figNo" select="concat(@figureNumber,@figureNumberVariant)"/>
<xsl:with-param name="prfigNo" select="concat(preceding-sibling::catalogSeqNumber/@figureNumber,preceding-sibling::catalogSeqNumber/@figureNumberVariant)" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="catalogSeqNumber-NI">
<xsl:param name="figNo"/>
<xsl:param name="prfigNo" />
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:value-of select=" ./itemSeqNumber/partRef/@partNumberValue"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<xsl:choose>
<xsl:when test="$figNo">
<fo:block>
<xsl:text> </xsl:text><xsl:value-of select="$figNo"/><xsl:text> </xsl:text> <xsl:value-of select="$prfigNo"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block />
</xsl:otherwise>
</xsl:choose>
</fo:table-cell>
<fo:table-cell>
<fo:block> <xsl:value-of select="concat(@item,@itemVariant)"/> </fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="./itemSeqNumber/quantityPerNextHigherAssy"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
预期输出:
<fo:table-row>
<fo:table-cell><fo:block>1025-129</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 02</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 050</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>1476-3248-1</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 02 02</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 040</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>2079-1302-1</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 01 02</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 000</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>3082-1604-1</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 01 01</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 010</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>63358</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 02 01</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 030</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>8910-276</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 01 02</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 000</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>8910-281</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 01 01</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 001</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
如果 node-set()
不起作用,那么您需要再次进行排序以获取上一项:
<xsl:key name="all" match="catalogSeqNumber" use="true()" />
<xsl:template name="SortParts">
<xsl:apply-templates
select="catalogSeqNumber[key('kfigNo', @figureNumber)]">
<xsl:sort select="itemSeqNumber/partRef/@partNumberValue"/>
<xsl:sort select="@figureNumber"/>
<xsl:sort select="@item"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="catalogSeqNumber">
<xsl:variable
name="figNo"
select="concat(@figureNumber,@figureNumberVariant)"/>
<xsl:variable name="current-position" select="position()"/>
<xsl:variable name="prfigNo">
<xsl:for-each select="key('all', true())">
<xsl:sort select="itemSeqNumber/partRef/@partNumberValue"/>
<xsl:sort select="@figureNumber"/>
<xsl:sort select="@item"/>
<xsl:if test="position() = $current-position - 1">
<xsl:value-of select="concat(@figureNumber,@figureNumberVariant)" />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<fo:table-row>
<fo:table-cell padding="3pt">
<fo:block>
<xsl:value-of
select="itemSeqNumber/partRef/@partNumberValue"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="3pt">
<fo:block>
<xsl:if test="$figNo">
<xsl:text> </xsl:text>
<xsl:value-of select="$figNo"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$prfigNo"/>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="3pt">
<fo:block>
<xsl:value-of select="concat(@item,@itemVariant)"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="3pt">
<fo:block>
<xsl:value-of
select="itemSeqNumber/quantityPerNextHigherAssy"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
我想访问排序列表中的前同级。我正在使用 Antenna House 6.2 和 XSLT 1.0。我尝试将 msxsl 扩展与 node-set()
一起使用,但调用 node-set()
失败。有人说在 1.0 中无法访问排序列表中的前同级,而其他人则提到了 Muenching Grouping 和使用 xsl:key
所以我现在正在尝试。我看过这个页面:http://www.jenitennison.com/xslt/grouping/muenchian.html
table 排序正确,但我一直无法弄清楚如何使用键检索已排序列表的前同级。我需要更多钥匙吗?我在 partNumberValue
上排序,然后在 figureNumber
上排序,figureNumber
可能有一个 figureNumberVariant
。任何建议表示赞赏。
XML:
<illustratedPartsCatalog>
<figure id="fig1">...</figure>
<catalogSeqNumber assyCode="05" figureNumber="01" indenture="0" item="000" subSubSystemCode="1" subSystemCode="1" systemCode="15">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>AT</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="8910-276">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>GGACC AIR VALVE ASSEMBLY</descrForPart></itemIdentData>
</partSegment><applicabilitySegment><usableOnCodeAssy>A</usableOnCodeAssy>
</applicabilitySegment></itemSeqNumber></catalogSeqNumber>
<catalogSeqNumber assyCode="05" figureNumber="01" indenture="0" item="001" itemVariant="A" subSubSystemCode="1" subSystemCode="2" systemCode="15">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>RF</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="8910-281">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>JJACC AIR VALVE ASSEMBLY</descrForPart></itemIdentData>
</partSegment><applicabilitySegment><usableOnCodeAssy>B</usableOnCodeAssy>
</applicabilitySegment></itemSeqNumber></catalogSeqNumber>
<catalogSeqNumber assyCode="05" figureNumber="01" indenture="1" item="000" subSubSystemCode="1" subSystemCode="1" systemCode="1">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>1</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="2079-1302-1">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>NAMEPLATE COVER</descrForPart></itemIdentData>
</partSegment>
<partLocationSegment>
<attachStoreShipPart attachStoreShipPartCode="1"/></partLocationSegment>
</itemSeqNumber></catalogSeqNumber>
<figure id="fig2">...</figure>
<catalogSeqNumber assyCode="05" figureNumber="02" indenture="1" item="030" subSubSystemCode="1" subSystemCode="2" systemCode="15">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>AR</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="63358">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>LOCK WIRE</descrForPart></itemIdentData></partSegment>
</itemSeqNumber></catalogSeqNumber>
<catalogSeqNumber assyCode="05" figureNumber="02" indenture="1" item="040" subSubSystemCode="1" subSystemCode="2" systemCode="15">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>1</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="1476-3248-1">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>SHIELD</descrForPart></itemIdentData></partSegment>
</itemSeqNumber></catalogSeqNumber>
<catalogSeqNumber assyCode="05" figureNumber="02" indenture="1" item="050" subSubSystemCode="1" subSystemCode="2" systemCode="15">
<itemSeqNumber itemSeqNumberValue="00A">
<quantityPerNextHigherAssy>2</quantityPerNextHigherAssy>
<partRef manufacturerCodeValue="01233" partNumberValue="1025-129">
</partRef>
<partSegment>
<itemIdentData>
<descrForPart>SCREW</descrForPart></itemIdentData></partSegment>
<partLocationSegment>
<attachStoreShipPart attachStoreShipPartCode="1"/></partLocationSegment>
</itemSeqNumber></catalogSeqNumber>
</illustratedPartsCatalog>
XSLT:
<xsl:key name="kfigNo" match="catalogSeqNumber" use="@figureNumber" />
<xsl:template match="illustratedPartsCatalog">
<xsl:apply-templates />
<fo:table>
<fo:table-header>
<fo:table-row>
<fo:table-cell>
<fo:block>PART</fo:block>
<fo:block>NUMBER</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>FIG</fo:block>
<fo:block>NO.</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>ITEM</fo:block>
<fo:block>NO.</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>QTY.</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:call-template name="SortParts"/>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template name="SortParts">
<xsl:for-each select="catalogSeqNumber[key('kfigNo', @figureNumber)]">
<xsl:sort select="concat(itemSeqNumber/partRef/@partNumberValue, @figureNumber,@item)"/>
<xsl:call-template name="catalogSeqNumber-NI">
<xsl:with-param name="figNo" select="concat(@figureNumber,@figureNumberVariant)"/>
<xsl:with-param name="prfigNo" select="concat(preceding-sibling::catalogSeqNumber/@figureNumber,preceding-sibling::catalogSeqNumber/@figureNumberVariant)" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="catalogSeqNumber-NI">
<xsl:param name="figNo"/>
<xsl:param name="prfigNo" />
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:value-of select=" ./itemSeqNumber/partRef/@partNumberValue"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<xsl:choose>
<xsl:when test="$figNo">
<fo:block>
<xsl:text> </xsl:text><xsl:value-of select="$figNo"/><xsl:text> </xsl:text> <xsl:value-of select="$prfigNo"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block />
</xsl:otherwise>
</xsl:choose>
</fo:table-cell>
<fo:table-cell>
<fo:block> <xsl:value-of select="concat(@item,@itemVariant)"/> </fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="./itemSeqNumber/quantityPerNextHigherAssy"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
预期输出:
<fo:table-row>
<fo:table-cell><fo:block>1025-129</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 02</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 050</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>1476-3248-1</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 02 02</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 040</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>2079-1302-1</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 01 02</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 000</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>3082-1604-1</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 01 01</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 010</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>63358</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 02 01</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 030</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>8910-276</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 01 02</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 000</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block>8910-281</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 01 01</fo:block></fo:table-cell>
<fo:table-cell><fo:block> 001</fo:block></fo:table-cell>
<fo:table-cell><fo:block>1</fo:block></fo:table-cell>
</fo:table-row>
如果 node-set()
不起作用,那么您需要再次进行排序以获取上一项:
<xsl:key name="all" match="catalogSeqNumber" use="true()" />
<xsl:template name="SortParts">
<xsl:apply-templates
select="catalogSeqNumber[key('kfigNo', @figureNumber)]">
<xsl:sort select="itemSeqNumber/partRef/@partNumberValue"/>
<xsl:sort select="@figureNumber"/>
<xsl:sort select="@item"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="catalogSeqNumber">
<xsl:variable
name="figNo"
select="concat(@figureNumber,@figureNumberVariant)"/>
<xsl:variable name="current-position" select="position()"/>
<xsl:variable name="prfigNo">
<xsl:for-each select="key('all', true())">
<xsl:sort select="itemSeqNumber/partRef/@partNumberValue"/>
<xsl:sort select="@figureNumber"/>
<xsl:sort select="@item"/>
<xsl:if test="position() = $current-position - 1">
<xsl:value-of select="concat(@figureNumber,@figureNumberVariant)" />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<fo:table-row>
<fo:table-cell padding="3pt">
<fo:block>
<xsl:value-of
select="itemSeqNumber/partRef/@partNumberValue"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="3pt">
<fo:block>
<xsl:if test="$figNo">
<xsl:text> </xsl:text>
<xsl:value-of select="$figNo"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$prfigNo"/>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="3pt">
<fo:block>
<xsl:value-of select="concat(@item,@itemVariant)"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="3pt">
<fo:block>
<xsl:value-of
select="itemSeqNumber/quantityPerNextHigherAssy"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>