|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Hi,
Can anyone help me devise a solution to this: My XML: --------- <results> <serviceResponse> <mmbi> <location>LW</location> <status>OK</status> </mmbi> <telNr>01243531098</telNr> <acctEntrys> <acctEntry>85.68</acctEntry> <acctEntry>00.00</acctEntry> <acctEntry>00.00</acctEntry> <acctEntry>85.68</acctEntry> </acctEntrys> </serviceResponse> <myFields> <field> <myName>hint</myName> <servicePath>/results/webServiceResponse/mmbi/location</servicePath> </field> <field> <myName>ONAcctEntry</myName> <servicePath>//acctEntrys/acctEntry</servicePath> </field> </myFields> </results> ---- what i want to do i loop through all of the myFields/field elements and produce an output like: S|hint|1|LW^ S|ONAccEntry|1|85.68^ S|ONAccEntry|2|00.00^ S|ONAccEntry|3|00.00^ S|ONAccEntry|4|85.68^ etc. where the format is: S|myName|occurance in service result|value from serviceResult i tried doing a for-each around each one like: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/> <!-- Start at the root of the response. --> <xsl:template match="/"> <!-- Loop around all the outputs that we require according to myFields. --> <xsl:for-each select="/results/myFields/field"> <!-- Remember the spg details we need. --> <xsl:variable name="myName"> <xsl:value-of select="./myName"/> </xsl:variable> <!-- Create a variable to hold the xpath of the web service variable that we want to retrieve. --> <xsl:variable name="xpathExpr"> <xsl:value-of select="./servicePath"/> </xsl:variable> <xsl:for-each select="$xpathExpr"> <xsl:value-of select="../../node()"/> <xsl:text>S|</xsl:text> <xsl:value-of select="$myName"/> <xsl:text>|</xsl:text> <xsl:number value="position()" format="1"/> <xsl:text>|</xsl:text> <xsl:value-of select="."/> <xsl:text>^</xsl:text> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet> unfortunately i have to have the serviceResponse node and the myFields seperate as they are made from diffrerent busness processes (i have just made one xml by appending them together). Appreciate any help! Regards, |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSLT problem with for-each and variables in select= |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|