XSLT 1.0 для объединения элементов

У меня есть XML, который имеет сложный элемент с именем ExternalRequestIDs. Мое требование состоит в том, чтобы объединить значения ExternalRequestID, поступающие во время выполнения. Если вход имеет 5 значений ExternalRequestID, то эти 5 значений необходимо объединить. XSL, который я создал, выполняет только статический перевод, я пытаюсь выполнить эту логику в xslt 1.0, я новичок в xslt. Пожалуйста, помогите

Исходный XML -

<?xml version="1.0" encoding="UTF-8" ?>
<RetrieveMIProcessRequest xmlns="http://xmlns.mycompany.com/RetrieveMI">
   <ExternalRequestIDs>
      <ExternalRequestID>ID1</ExternalRequestID>
   </ExternalRequestIDs>
   <ExternalRequestIDs>
      <ExternalRequestID>ID2</ExternalRequestID>
   </ExternalRequestIDs>
   <ExternalRequestIDs>
      <ExternalRequestID>ID3</ExternalRequestID>
   </ExternalRequestIDs>
   <SourceSystem>SourceSystemName</SourceSystem>
 </RetrieveMIProcessRequest>

Преобразование, созданное для объединения значений ExternalRequestID —

<xsl:template match="/">
    <ns0:RetrieveMIProcessRequest>
      <xsl:for-each select="/ns0:RetrieveMIProcessRequest/ns0:ExternalRequestIDs">
        <xsl:variable name="ExtId"
                      select="concat(&quot;'&quot;,/ns0:RetrieveMIProcessRequest/ns0:ExternalRequestIDs[1]/ns0:ExternalRequestID,&quot;','&quot;,/ns0:RetrieveMIProcessRequest/ns0:ExternalRequestIDs[2]/ns0:ExternalRequestID&quot;'&quot;)"/>
        <ns0:ExternalRequestIDs>
          <ns0:ExternalRequestID>
            <xsl:value-of select="$ExtId"/>
          </ns0:ExternalRequestID>
        </ns0:ExternalRequestIDs>
      </xsl:for-each>
      <ns0:SourceSystem>
        <xsl:value-of select="/ns0:RetrieveMIProcessRequest/ns0:SourceSystem"/>
      </ns0:SourceSystem>
          </ns0:RetrieveMIProcessRequest>
  </xsl:template>

Выход после преобразования -

<?xml version = '1.0' encoding = 'UTF-8'?>
<ns0:RetrieveMIProcessRequest xmlns:ns0="http://xmlns.mycompany.com/RetrieveMI">
   <ns0:ExternalRequestIDs>
      <ns0:ExternalRequestID>'ID1','ID2'</ns0:ExternalRequestID>
   </ns0:ExternalRequestIDs>
   <ns0:ExternalRequestIDs>
      <ns0:ExternalRequestID>'ID1','ID2'</ns0:ExternalRequestID>
   </ns0:ExternalRequestIDs>
   <ns0:ExternalRequestIDs>
      <ns0:ExternalRequestID>'ID1','ID2'</ns0:ExternalRequestID>
   </ns0:ExternalRequestIDs>
   <ns0:SourceSystem>SourceSystemName</ns0:SourceSystem>

</ns0:RetrieveMIProcessRequest>

Ожидаемый результат -

<?xml version = '1.0' encoding = 'UTF-8'?>
<ns0:RetrieveMIProcessRequest xmlns:ns0="http://xmlns.mycompany.com/RetrieveMI">
<ns0:ExternalRequestIDs>
 <ns0:ExternalRequestID>'ID1','ID2','ID3'</ns0:ExternalRequestID>
</ns0:ExternalRequestIDs>
  <ns0:SourceSystem>SourceSystemName</ns0:SourceSystem>

</ns0:RetrieveMIProcessRequest>

Это должно быть достигнуто при запуске на основе значений ExternalRequestID, поступающих во входном запросе. Если вход имеет 5 значений ExternalRequestID, то значения необходимо объединить.


person Vinu    schedule 01.09.2015    source источник
comment
Я не верю, что с такой таблицей стилей можно получить результат, который вы нам показываете (фактический результат, а не ожидаемый). Можете ли вы обновить свой вопрос?   -  person potame    schedule 01.09.2015
comment
Мое требование состоит в том, чтобы объединить значения ExternalRequestID из запроса и сопоставить их с ответом. Если есть 5 значений ExternalRequestID, все они должны быть объединены и сопоставлены с ответом. Есть ли какие-либо другие действия в XSLT 1.0?   -  person Vinu    schedule 01.09.2015
comment
Можете ли вы также объяснить, как вы получаете значение ID1, ...? Это только подстрока ExternalRequestID1?   -  person potame    schedule 01.09.2015
comment
Отредактировал мой вопрос.. Только значения «ExternalRequestID» должны быть объединены, нет необходимости брать подстроку, извините за путаницу.   -  person Vinu    schedule 01.09.2015


Ответы (1)


Хорошо, этот шаблон должен соответствовать вашим потребностям:

<xsl:template match="/">
    <ns0:RetrieveMIProcessRequest>
            <ns0:ExternalRequestIDs>
                <ns0:ExternalRequestID>
                    <!-- Loop on all ExternalRequestID and concatenate the textual values -->
                    <xsl:for-each select="/ns0:RetrieveMIProcessRequest/ns0:ExternalRequestIDs/ns0:ExternalRequestID">
                        <xsl:text>'</xsl:text>
                        <xsl:value-of select="."/>
                        <xsl:text>'</xsl:text>
                        <xsl:if test="following::ns0:ExternalRequestID">
                            <xsl:text>,</xsl:text>
                        </xsl:if>
                    </xsl:for-each>
                </ns0:ExternalRequestID>
            </ns0:ExternalRequestIDs>
        <ns0:SourceSystem>
            <xsl:value-of select="/ns0:RetrieveMIProcessRequest/ns0:SourceSystem"/>
        </ns0:SourceSystem>
    </ns0:RetrieveMIProcessRequest>
</xsl:template>

Вывод, который я получаю:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:RetrieveMIProcessRequest xmlns:ns0="http://xmlns.mycompany.com/RetrieveMI">
    <ns0:ExternalRequestIDs>
      <ns0:ExternalRequestID>'ID1','ID2','ID3'</ns0:ExternalRequestID>
    </ns0:ExternalRequestIDs>
  <ns0:SourceSystem>SourceSystemName</ns0:SourceSystem>
</ns0:RetrieveMIProcessRequest>
person potame    schedule 01.09.2015