0

I have xml file with node

<air:AirAvailInfo ProviderCode="1G">
  <air:BookingCodeInfo BookingCounts="C4|Z4|I4|D4|Y4|W4|Q4|E4|G4|T4|N4|B4|X4|U4|O4|V4|H4|L4|K4"/>
</air:AirAvailInfo>

It is code in xslt 1.0. How change only one sector in node? How can I do this in result?

<info>
  <code>H</code>
  <status>4</status>
</info>

Thanks!

3
  • That is just going to depend on how those codes and status are selected. Try to explain what you are trying to do in a general way.
    – Pablo Pozo
    Feb 28, 2013 at 11:07
  • So to say that I know that me need only select "H" from this list
    – Vitmais
    Feb 28, 2013 at 11:26
  • And the values from that list could be in a different order and the status of the code (4, in the code you posted) could be different than 4? Besides, could be more than one H element in that list? Or each element in that least is unique and have the same syntax: LETTER + NUMBER?
    – Pablo Pozo
    Feb 28, 2013 at 11:35

1 Answer 1

0

My answer assumes the following:

  • All the elements of the list in BookingCounts are formed by the concatenation of a LETTER and a NUMBER. The length of the number is always 1.

  • All of the elements on the list are unique, where the unique relationship is defined solely by the uniqueness of the letter. So we cannot find elements H2 H5 in the same list.

  • OP only needs to retrieve the H element in the list.

A solution following these assumptions could be:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:air="http://airnamespace.com" version="1.0">
    <xsl:output method="xml" indent="yes"/>

    <!-- Match the attribute BookingCounts inside air:BookingCodeInfo -->
    <xsl:template match="air:BookingCodeInfo">
        <info>
            <code>H</code>
            <status><xsl:value-of select="substring(substring-after(@BookingCounts, 'H'), 1, 1)" /></status>
        </info>
    </xsl:template>

</xsl:stylesheet>

If some of these assumptions are not right, tell me and I will change the code.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.