我有数据作为我的输入XML,如下所示:
<Travelers>
<Surname>GROUPNAME</Surname><PNRNameNumber>1</PNRNameNumber><PassengerNumber>1</PassengerNumber>
<TravelerSegments>
<SegmentNumber>1</SegmentNumber>
<SeatLegRecords>
<SeatBoardPoint>ORD</SeatBoardPoint>
<SeatOffPoint>SFO</SeatOffPoint>
<SeatNumbers>30A</SeatNumbers>
<SeatNumbers>30B</SeatNumbers>
<SeatNumbers>30C</SeatNumbers>
<SeatNumbers>30D</SeatNumbers>
<SeatNumbers>30E</SeatNumbers>
<SeatNumbers>30F</SeatNumbers>
<SeatNumbers>30G</SeatNumbers>
<SeatNumbers>30H</SeatNumbers>
<SeatNumbers>31A</SeatNumbers>
</SeatLegRecords>
<SeatLegRecords>
<SeatBoardPoint>SFO</SeatBoardPoint>
<SeatOffPoint>LAX</SeatOffPoint>
<SeatNumbers>30A</SeatNumbers>
<SeatNumbers>30B</SeatNumbers>
<SeatNumbers>30C</SeatNumbers>
<SeatNumbers>30D</SeatNumbers>
<SeatNumbers>30E</SeatNumbers>
<SeatNumbers>30F</SeatNumbers>
<SeatNumbers>30G</SeatNumbers>
<SeatNumbers>30H</SeatNumbers>
<SeatNumbers>31A</SeatNumbers>
</SeatLegRecords>
</TravelerSegments>
我希望我的输出显示如下 -
{
[ "30A","30B",30C","30D","30E","30F","30G","30H","31A"],
[ "30A","30B",30C","30D","30E","30F","30G","30H","31A"]
}
有人可以帮助我使用 XSLT 1.0 吗?我知道这在 XSLT 2.0 中很容易。但是,我的环境中没有可用的 XLST 2.0。
Try this.
<xsl:template match="TravelerSegments">
<xsl:value-of select="'{ '"/>
<xsl:apply-templates select=".//SeatLegRecords"/>
<xsl:value-of select="' }'"/>
</xsl:template>
<xsl:template match="SeatLegRecords">
<xsl:if test="position() > 1">
<xsl:value-of select="', '"/>
</xsl:if>
<xsl:value-of select="'['"/>
<xsl:apply-templates select=".//SeatNumbers"/>
<xsl:value-of select="']'"/>
</xsl:template>
<xsl:template match="SeatNumbers">
<xsl:if test="position() > 1">
<xsl:value-of select="','"/>
</xsl:if>
<xsl:value-of select="concat('"',.,'"')"/>
</xsl:template>
<xsl:template match="node()">
<xsl:apply-templates select="node()"/>
</xsl:template>