XSLT 1.0 get node set

ewinlesov

New Member
i am beginner in XSLT. I am using XSLT to transform XML to XML through JDK 6.Below is the Source XML which i received from the web service.Source XML:\[code\]<Response> <data> <route type="OUTBOUND"> <Include>AA</Include> <Include>BB</Include> <Include>CC</Include> </route> <route type="INBOUND"> <Include>XX</Include> <Include>YY</Include> <Include>ZZ</Include> </route> </data> <result> <Flights type="OUTBOUND"> <Flight> <Airline>AA</Airline> </Flight> <Flight> <Airline>BB</Airline> </Flight> <Flight> <Airline>CC</Airline> </Flight> <Flight> <Airline>XX</Airline> </Flight> <Flight> <Airline>YY</Airline> </Flight> <Flight> <Airline>ZZ</Airline> </Flight> </Flights> <Flights type="INBOUND"> <Flight> <Airline>AA</Airline> </Flight> <Flight> <Airline>BB</Airline> </Flight> <Flight> <Airline>CC</Airline> </Flight> <Flight> <Airline>XX</Airline> </Flight> <Flight> <Airline>YY</Airline> </Flight> <Flight> <Airline>ZZ</Airline> </Flight> </Flights> </result></Response>\[/code\]XSLT:\[code\]<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt"> <xsl:output method="xml" indent="yes" /> <xsl:template match="Response"> <xsl:element name="Result"> <xsl:apply-templates select="result/Flights"/> </xsl:element> </xsl:template> <xsl:template match="Flights"> <xsl:variable name="PrefAirlines"> <xsl:choose> <xsl:when test="current()/@type = 'OUTBOUND'"> <xsl:value-of select="//route[@type='OUTBOUND']/Include"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="//route[@type='INBOUND']/Include"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:apply-templates select="Flight[Airline=$PrefAirlines]"/> </xsl:template> <xsl:template match="Flight"> <xsl:element name="FilterFlight"> <xsl:value-of select="Airline"/> </xsl:element> </xsl:tempalte></xsl:stylesheet>\[/code\]When i apply above XSLT on the source XML i get following output XML.OutputXML:\[code\]<Result> <FilterFlight>AA</FilterFlight> <FilterFlight>XX</FilterFlight></Result>\[/code\]Expected output:\[code\]<Result> <FilterFlight>AA</FilterFlight> <FilterFlight>BB</FilterFlight> <FilterFlight>CC</FilterFlight> <FilterFlight>XX</FilterFlight> <FilterFlight>YY</FilterFlight> <FilterFlight>ZZ</FilterFlight></Result>\[/code\]The problem is within the logic of creating variable \[code\]PrefAirlines\[/code\].I have tried below approach as well but didn't get the expected output.\[code\]<xsl:variable name="PrefAirlines"> <xsl:choose> <xsl:when test="current()/@type = 'OUTBOUND'"> <xsl:value-of select="exslt:node-set(//route[@type='OUTBOUND']/Include)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="exslt:node-set(//route[@type='INBOUND']/Include)"/> </xsl:otherwise> </xsl:choose></xsl:variable>\[/code\]Is there any function available using which i can get the node set instead of single value?Please help.
 
Back
Top