Jump to content

Looking for correct Element / Function to use


MKline

Recommended Posts

Hello,I'm fairly new to XSLT and have gone through the Tutorials, however I'm not sure which Element / Function I would use to loop through a very large XML file that I have. Below is the XSL which gives me 1 line of output that I am able to save in a .csv file. The issue is, the XML file is huge and the data which is captured by the 2nd <xsl:value-of select statement may repeat over 100 times until the end of the file (it is remittance data with a new shipment ID number each loop). How can I re-write the XSL to ensure it flows through to the end and gives me a line for each match? If you need a sampling of the XML, please let me know and I will post that as well. :) Thanks much!<xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/><!-- <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="Item"> <xsl:element name="{@Name}"> <xsl:value-of select="Value"/> </xsl:element> </xsl:template>--><xsl:template match="/"> <xsl:value-of select="'ShipperID, Pay Item, Purchase Order Number, Seller Invoice ID, Order Number, Received, Quantity, Unit Price, BP Number, CK Number, '"/> <xsl:value-of select="concat(/FormData/Form[1]/Form[3]/Form[1]/Item[1]/Value, ' ', /FormData/Form[1]/Form[3]/Form[1]/Item[2]/Value, ',', /FormData/Form[1]/Form[3]/Form[1]/Item[3]/Value[1], ' ', /FormData/Form[1]/Form[3]/Form[1]/Item[4]/Value[1], ',', /FormData/Form[1]/Form[3]/Form[1]/Form[1]/Group[1]/Item[1]/Value[1], ' ', /FormData/Form[1]/Form[3]/Form[1]/Form[1]/Group[1]/Item[2]/Value[1], ',', /FormData/Form[1]/Form[3]/Form[1]/Form[1]/Group[2]/Item[1]/Value[1], ' ', /FormData/Form[1]/Form[3]/Form[1]/Form[1]/Group[2]/Item[2]/Value[1], ',', /FormData/Form[1]/Form[3]/Form[1]/Form[3]/Form[1]/Item[1]/Value[1], ' ', /FormData/Form[1]/Form[3]/Form[1]/Form[3]/Form[1]/Item[2]/Value[1], ',', /FormData/Form[1]/Form[3]/Form[1]/Form[3]/Form[1]/Form[1]/Group[1]/Item[1]/Value[1], ' ', /FormData/Form[1]/Form[3]/Form[1]/Form[3]/Form[1]/Form[1]/Group[1]/Item[2]/Value[1], ',', /FormData/Form[1]/Form[3]/Form[1]/Form[3]/Item[1]/Value, ',', /FormData/Form[1]/Form[3]/Form[1]/Form[3]/Item[2]/Value, ',', /FormData/Form[1]/Form[3]/Form[1]/Form[3]/Item[3]/Value, ',', /FormData/Form[1]/Form[3]/Form[1]/Form[3]/Form[1]/Item[4]/Value, '')"/></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

You haven't read anything. Not in W3Schools' tutorials anyway. One of the very first examples shown is exactly the thing you need: the <xsl:for-each> element.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...