0

我有带有节点的 xml 文件

<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>

它是 xslt 1.0 中的代码。如何仅更改节点中的一个扇区?我怎样才能做到这一点?

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

谢谢!

4

1 回答 1

0

我的回答假设如下:

  • BookingCounts 中列表的所有元素都是由 LETTER 和 NUMBER 串联而成的。数字的长度始终为 1。

  • 列表中的所有元素都是唯一的,其中唯一关系仅由字母的唯一性定义。所以我们无法在同一个列表中找到元素 H2 H5。

  • OP 只需要检索列表中的 H 元素。

遵循这些假设的解决方案可能是:

<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>

如果其中一些假设不正确,请告诉我,我将更改代码。

于 2013-02-28T11:48:17.537 回答