xsl:sort с предшествующим братом XSLT 1.0 XSL-FO muenchian xsl:key

Я хотел бы получить доступ к предыдущим братьям и сестрам в отсортированном списке. Я использую Antenna House 6.2 и XSLT 1.0. Я пытался использовать расширение msxsl с node-set(), но вызовы node-set() не удались. Некоторые говорят, что доступ к предыдущему брату в отсортированном списке не может быть выполнен в 1.0, а другие упоминали группировку Мюнхинга и использование xsl:key, поэтому я пробую это сейчас. Я просмотрел эту страницу: http://www.jenitennison.com/xslt/grouping/muenchian.html

Таблица отсортирована правильно, но я не смог понять, как получить предшествующий брат отсортированного списка с помощью ключа. Мне нужно больше ключей? Я сортирую по 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>

person Caroline    schedule 04.05.2017    source источник
comment
В вашем примере показан один конкретизированный catalogSeqNumber, но вопрос, сортировка и результаты, похоже, зависят от наличия как минимум двух catalogSeqNumber. Можете ли вы добавить хотя бы еще один элемент catalogSeqNumber, который содержит достаточно информации для получения результата, а также показывает, что должны содержать результирующие строки таблицы?   -  person Tony Graham    schedule 04.05.2017
comment
Я обновил вопрос, спасибо, Тони.   -  person Caroline    schedule 04.05.2017
comment
Возможный дубликат Выбор следующего брата отсортированного узла   -  person michael.hor257k    schedule 04.05.2017
comment
select="catalogSeqNumber[key('kfigNo', @figureNumber)]" не имеет для меня смысла. Каждый catalogSeqNumber в вашем XML имеет @figureNumber, и этот @figureNumber всегда будет иметь значение, возвращаемое из поиска key(), поэтому вы все равно выбираете каждый catalogSeqNumber.   -  person Tony Graham    schedule 05.05.2017
comment
Если вы хотите отсортировать по трем элементам, используйте три отдельных xsl:sort, например: <xsl:sort select="itemSeqNumber/partRef/@partNumberValue"/><xsl:sort select="@figureNumber"/><xsl:sort select="@item)"/>.   -  person Tony Graham    schedule 05.05.2017


Ответы (1)


Если 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>
person Tony Graham    schedule 05.05.2017