xml - XSLT - Accessing outer element with inner loop of nested for-each loop -
i new xslt , have problem requires me access values elements in outer loop of nested for-each within inner loop. xml looks follows
<searchresults> <journeygroup> <journeygroupnum>1</journeygroupnum> <journeydetails> <flightsegments>1</flightsegments> <journeyid>1</journeyid> <currency>usd</currency> <fare>399.00</fare> <taxes>99.00</taxes> <flights> <segmentid>1</segmentid> <legid>1</legid> <marketingcarrier>dl</marketingcarrier> <operatingcarrier>dl</operatingcarrier> <flightnum>9695</flightnum> </flights> </journeydetails> <journeydetails> <flightsegments>1</flightsegments> <journeyid>2</journeyid> <currency>usd</currency> <fare>459.00</fare> <taxes>129.00</taxes> <flights> <segmentid>1</segmentid> <legid>1</legid> <marketingcarrier>aa</marketingcarrier> <operatingcarrier>aa</operatingcarrier> <flightnum>5070</flightnum> </flights> </journeydetails> </journeygroup> </searchresults>
an extract of xslt document looks follows
<table> <xsl:for-each select="searchresults/journeygroup/journeydetails"> <xsl:for-each select="flights[segmentid='1']"> <tr> <td><xsl:value-of select="marketingcarrier"/></td> <td><xsl:value-of select="operatingcarrier"/></td> <td><xsl:value-of select="flightnum"/></td> <!-- here add columns currency , fare outer loop --> <td>currency</td> <td>fare</td> </tr> </xsl:for-each> </xsl:for-each> <table>
how access values currency , fare nodes in outer loop inner for-each loop.
you can access parent relatively:
<xsl:value-of select="../currency"/>
or capture outside loop current node variable , access inside:
<table> <xsl:for-each select="searchresults/journeygroup/journeydetails"> <xsl:variable name="journeydetails" select="."/> <xsl:for-each select="flights[segmentid='1']"> <tr> <td><xsl:value-of select="marketingcarrier"/></td> <td><xsl:value-of select="operatingcarrier"/></td> <td><xsl:value-of select="flightnum"/></td> <!-- here add columns currency , fare outer loop --> <td><xsl:value-of select="$journeydetails/currency"/></td> <td><xsl:value-of select="$journeydetails/fare"/></td> </tr> </xsl:for-each> </xsl:for-each> </table>
Comments
Post a Comment