I have the following xml input
sample 1:
<root>
<SeatElementNumber>1</SeatElementNumber>
<CommandRS>
<Response>MI<X>TKT NBR< ></Response>
</CommandRS>
<Create>... </Create>
</root>
sample 2:
<root>
<SeatElementNumber>1</SeatElementNumber>
<CommandRS>
<Response>MI<X>TKT NBR<1234></Response>
</CommandRS>
<Create>... </Create>
</root>
I currently have code which will extract the values between the lt and gt in order to build a Request xml as follows:
<CommandRQ><Request><X><1234></Request></CommandRQ>
However, if the the TKT NBR in the input is null (like in sample 1), i want to use the tktNumber i stored in a prior variable. How can i do this in xsl?
This is code I have so far.
<xsl:key name="TktMatch" match="View/Identify/Info[TicketNumber/@Status='TICKETED']/SegmentElementNumber" use="." />
<xsl:variable name="SeatSegment" select="/root/Create/Other/Seat[position() = 1]/SegmentIDRef"/>
<xsl:variable name="TktNumber" select="key('TktMatch', $SeatSegment)/@TicketNumber"/>
<xsl:template match="CommandRS">
<xsl:apply-templates/>
</CommandRQ>
</xsl:template>
<xsl:template match="Response">
<Request>
<xsl:call-template name="strip-between-tags">
<xsl:with-param name="str" select="."/>
</xsl:call-template>
</Request>
</xsl:template>
<xsl:template name="strip-between-tags">
<xsl:param name="str"/>
<xsl:choose>
<xsl:when test="contains($str, '<')">
<xsl:text disable-output-escaping="yes"><</xsl:text>
<xsl:value-of select="substring-before(substring-after($str, '<'), '>')"></xsl:value-of>
<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:call-template name="strip-between-tags">
<xsl:with-param name="str" select="substring-after($str, '>')"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
ASKER
your code worked (thanks) but when I execute the xsl (using Visual Studios) it seems to be returning the values that are in the <Create> node
The reponse builds as follows
<CommandRQ><Request><X><12
2
1
82D
1
2
RA
SRT
SEAT
Pre-reserved Seating
82D