Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Exporting records into xml using style sheet problem with template

Featured Replies

I've spent a few days and just can't figure this out .... 2 basic problems.

Desired result :


<Database>

<Item>

<Price>14.95</Price>

<SKU>12345</SKU>

</Item>

<Item>

<Price Currency="USD">7.95</Price>

<SKU>12346</SKU>

</Item>

<Item>

<Price Currency="USD">14.95</Price>

<SKU>12347</SKU>

</Item>

</Database>





I'm almost fine with each 'Item' section but......





1. I can't get the <Price Currency="USD"> to show. I only get <Price>



Should I even be using a template? I don't know why I can't figure this out .... UGH.



2. I can't get the Envelope tag in without an error .... 'Expected end of tag Envelope'



My basic code so far for this section is :


<xsl:template match="fmp:FMPXMLRESULT">

    <xsl:call-template name="header"/>

        <xsl:for-each select="fmp:RESULTSET/fmp:ROW">

            <Item>

<!-- I tried this but nothing shows up besides Price -->

       	        <xsl:attribute name="Currency"><xsl:value-of select="USD" /></xsl:attribute>

       	        <Price><xsl:value-of select="fmp:COL[2]/fmp:DATA" /></Price>

       	   	 <SKU><xsl:value-of select="fmp:COL[1]/fmp:DATA" />></SKU>

       	 </Item>

            <xsl:value-of select="$newrecord"/>

        </xsl:for-each>

    </xsl:template>

<xsl:template name="header">

<Database>

<xsl:value-of select="$newrecord"/>

</xsl:template>

<xsl:template name="footer">

</Database>

</xsl:template>

Side Notes:

No .... this is not the exact xml or xsl. It is a concept... premise to build upon.

I don't want to change the xml.

If I made a minor mistake in the post I'm sorry...

Help PLEASE !!

	   		    <xsl:attribute name="Currency"><xsl:value-of select="USD" /></xsl:attribute>


The correct syntax is:

2. I can't get the Envelope tag in without an error .... 'Expected end of tag Envelope'

I don't see "Envelope" anywhere in your code example. However, I believe this is not valid XML:

<xsl:template name="footer">

</Database>

</xsl:template>

In XML, all elements must be properly nested within each other. You cannot open an element somewhere, then close it inside another element.

<xsl:attribute name="Currency">USD</xsl:attribute>




Or you could do simply:




<Price Currency="USD"><xsl:value-of select="fmp:COL[2]/fmp:DATA" /></Price>
  • Author

Thanks for the response....

I'm not sure how this will display because when I click to quote I'm getting :

"The number of opening quote tags does not match the number of closing quote tags." from the forum.....

Ssssooooo I'm gonna jst reply without quoting you.......

<xsl:attribute name="Currency">USD</xsl:attribute>


Oddly still nothing shows within the Price node section as needed. Do I need to do something else to call it.... I've never tried this before.




<Price Currency="USD"><xsl:value-of select="fmp:COL[2]/fmp:DATA" /></Price>


This works and I could use it but it doesn't leave me the possibility of in the future using a field to make the Currency attribute adjustable.

i.e. USD or EUR or other.....

I was hoping to use the first so I could possibly later use something like :


<xsl:attribute name="Currency"><xsl:value-of select="fmp:COL[#]/fmp:DATA" /></xsl:attribute>

As to the "Envelope" ....Oops ... should've been 'Database'

I realize that the XML isn't correct but I can't figure out how to write a style sheet so that the records appear within the opening and closing 'Database' tags .....

Thus my main problem.... how to do it.

  • Author

Problem 1 solved ....


<Price>

<xsl:attribute name="Currency"><xsl:value-of select="fmp:COL[3]/fmp:DATA" /></xsl:attribute>

<xsl:value-of select="fmp:COL[4]/fmp:DATA" />

</Price>





Lets me set a field and gives desired results....


<Price Currency="USD">14.95</Price>




Now to figure out the main problem.................


<Database>

... all my records exported ..

</Database>

Does this work for you?

items.zip

  • Author

Gonna check that .... thank you!

Shows as empty ..... but that's OK. I appreciate the effort.

However I guess a new day brings a fresh mind.

Suddenly everything starts to flow again.

I ditched the template for now and just went with :




<xsl:template match="fmp:FMPXMLRESULT">

	<Database>

		<xsl:for-each select="fmp:RESULTSET/fmp:ROW">

			<Item>

	   		 <SKU><xsl:value-of select="fmp:COL[1]/fmp:DATA" /></SKU>

	   			<!-- <StandardPrice currency="USD"> -->

	   		 <Price>

				<xsl:attribute name="Currency"><xsl:value-of select="fmp:COL[2]/fmp:DATA" /></xsl:attribute>

	   		 <xsl:value-of select="fmp:COL[3]/fmp:DATA" /></Price>

			</Item>

			<xsl:value-of select="$newrecord"/>

		</xsl:for-each>

		</Database>

	</xsl:template>

My apologies if I've oopsed in retyping to follow the original example......

  • 4 weeks later...
  • Author

Coming back to this because I just can't figure out why after export I open the XML in Notepad++ and have EXTRA returns ....

i.e.

<Message>



<MessageID>1</MessageID>



<Price>



<SKU>SKU1</SKU>



<StandardPrice currency="USD">4.95</StandardPrice>



</Price>



</Message>



<Message>



<MessageID>2</MessageID>



<Price>



<SKU>SKU2</SKU>



... yet in the normal Notepad it looks fine.

Attached is the Style Sheet to look over or if anyone needs it ...... and the xml MWS_Price_XML_USD.xmlAmazonReprice.zip

Your stylesheet inserts a CRLF between each record - in Windows, this should be read as a single return.

In any case, returns between XML elements have no significance in a XML document. The part in your stylesheet that defines the $newrecord variable and the part that inserts it are both entirely redundant.

  • Author

HHHuuummm ... OK and thank you.

However that still doesn't change the output any in Notepad ++ .....

<Message>



<MessageID>1</MessageID>



<Price>



<SKU>SKU1</SKU>



<StandardPrice currency="USD">.95</StandardPrice>



</Price>



</Message>



<Message>



<MessageID>2</MessageID>



<Price>



<SKU>SKU2</SKU>



<StandardPrice currency="USD">12.24</StandardPrice>



</Price>



</Message>



<Message>

Edit : I can only assume extra characters are being put in .....

It's possible - but it doesn't matter, so why bother? Did you run into any difficulties with the result being accepted by the target application?

  • Author

Been out-of-town and broke mt laptop screen ... rough trip.

Anyway .....

Did you run into any difficulties with the result being accepted by the target application?

No ...

so why bother?

It might not hurt now but what if it does latter? Why not firgure it out while I'm working on it instead of trying to find what's wrong if it breaks down the road ?

But it won't hurt later - the extraneous returns are completely ignored by XML and any XML reader. They're only interested in data enclosed within correctly formatted tags. It's also why a lot of XML presentation is indented with tabs - also ignored...

If you want to find out what (if anything) is going on, I'd suggest you make an effort to download my example in post #5 above and see what you get.

You may need to get a zip extracting application that's compatible with Windows 7.

  • Author

If you want to find out what (if anything) is going on, I'd suggest you make an effort to download my example in post #5 above and see what you get.

Possibly you could make an effort to read Post #6 showing that I did....

You may need to get a zip extracting application that's compatible with Windows 7.

Yes it could just be me ... and probably is ... but I do have one, thank you, and it seems to open everything else just fine.

ANYWAY ... thank you for your time.

I did read the post where you said it shows as empty. I assure you it is not.

On my part, I make the effort to zip the files using a 3rd-party utility that removes the Mac-only stuff that so confuses Windows users. Your reaction proves again that no good deed goes unpunished...

  • Author

My 'reaction'(s) always come directly from your ability to turn a good dead ... and for that matter seemingly any post I make ... into finding a way to make a snide remark.

I'd suggest you make an effort to download my example ....

Well if you read my post then you know that I DID make an effort ... I DID download it .... I DID open it ... I DID thank you for the effort.

I apologize for thinking this time MIGHT be different ...........

Side Note: I see there have been (at this point) 17 downloads. Several are mine from the same machine and then again from a different one.

ANY windows people out there that can explain why every download shows empty please let me know .....

My 'reaction'(s) always come directly from your ability to turn a good dead ... and for that matter seemingly any post I make ... into finding a way to make a snide remark.

I have no idea what are you talking about. And frankly, no wish to find out. Have a nice day.

ANY windows people out there that can explain why every download shows empty please let me know .....

It isn't empty, but a windows protection do not let open it with the default unzip app. Try WinRar

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.