XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old June 1st, 2003, 12:02 PM
Dazman Dazman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: UK
Posts: 2 Dazman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy XSLT problem with for-each and variables in select=

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,

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSLT problem with for-each and variables in select=


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway