Cabinetman Posted August 5, 2011 Posted August 5, 2011 I just can't quite see this one.... In this instance I have 2 ITEMS and 6 ITEM but sometimes I only have 1 ITEMS. If I want to import all 6 records <ITEM> ..... and they come in under ITEMS but not the same one... where do I put another for each? Or must I do something else?? XML <ITEMS> <ITEM>1</ITEM> <ITEM>2</ITEM> <ITEM>3</ITEM> <ITEM>4</ITEM> <ITEMS> <ITEM>1</ITEM> <ITEM>2</ITEM> <xsl:for-each select="Response/ITEMS"> only gives me 2 records. <xsl:for-each select="Response/ITEMS/ITEM"> gives me nothing. <RESULTSET> <xsl:attribute name="FOUND">1</xsl:attribute> <xsl:for-each select="Response/ITEMS"> <ROW> <xsl:attribute name="MODID">0</xsl:attribute> <xsl:attribute name="RECORDID">1</xsl:attribute> <COL> <DATA> <xsl:value-of select="whatever"/> </DATA> </COL> </ROW> </xsl:for-each> </RESULTSET>
comment Posted August 5, 2011 Posted August 5, 2011 <xsl:for-each select="Response/ITEMS"> only gives me 2 records. I don't see a <Response> element in your XML. It would be best to post a complete example, so we can see the context.
Cabinetman Posted August 5, 2011 Author Posted August 5, 2011 It is. I just don't want to post a bunch of code........ It seems like it's not that hard & I should know how to do this. I guess to be more exact it should be....... <Response> <ITEMS> <ITEM>1</ITEM> <ITEM>2</ITEM> <ITEM>3</ITEM> <ITEM>4</ITEM> </ITEMS> <ITEMS> <ITEM>1</ITEM> <ITEM>2</ITEM> </ITEMS> </Response>
comment Posted August 5, 2011 Posted August 5, 2011 Try: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:template match="/"> <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult"> <ERRORCODE>0</ERRORCODE> <PRODUCT BUILD="" NAME="" VERSION=""/> <DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/> <METADATA> <FIELD NAME="Item" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/> </METADATA> <RESULTSET FOUND=""> <xsl:for-each select="Response/ITEMS/ITEM"> <ROW MODID="" RECORDID=""> <COL><DATA><xsl:value-of select="."/></DATA></COL> </ROW> </xsl:for-each> </RESULTSET> </FMPXMLRESULT> </xsl:template> </xsl:stylesheet>
Cabinetman Posted August 5, 2011 Author Posted August 5, 2011 Thanks.... I didn't want anyone to have to write all that but thank you! I almost had that.... took it out of another stylesheet I had. It works fine but I can foresee a possible dilemma later. What happens if I add objects under ITEM ? <Response> <ITEMS> <ITEM> <NAME>John Doe</NAME> <PHONE>555-555-1212</PHONE> </ITEM> <ITEM> <NAME>John Doe</NAME> <PHONE>555-555-1212</PHONE> </ITEM> <ITEM> <NAME>John Doe</NAME> <PHONE>555-555-1212</PHONE> </ITEM> <ITEM> <NAME>John Doe</NAME> <PHONE>555-555-1212</PHONE> </ITEM> </ITEMS> <ITEMS> <ITEM> <NAME>John Doe</NAME> <PHONE>555-555-1212</PHONE> </ITEM> <ITEM> <NAME>John Doe</NAME> <PHONE>555-555-1212</PHONE> </ITEM> </ITEMS> </Response> Now I have multiple ITEMS and also multiple ITEM ??
comment Posted August 5, 2011 Posted August 5, 2011 What happens if I add objects under ITEM ? You'll need to do two things: 1. Place a FIELD element in the METADATA section for each field you want to import (Name and Phone in your example); 2. Change this: <ROW MODID="" RECORDID=""> <COL><DATA><xsl:value-of select="."/></DATA></COL> </ROW> to: <ROW MODID="" RECORDID=""> <COL><DATA><xsl:value-of select="NAME"/></DATA></COL> <COL><DATA><xsl:value-of select="PHONE"/></DATA></COL> </ROW>
Cabinetman Posted August 6, 2011 Author Posted August 6, 2011 BTW - Thanks again .... We just had our first grand-kid so I got busy and didn't get a chance to work on this. I don't know what I was doing wrong because after all is said and done it looks just like what I had. Well I take that back ! While writing this I got to wondering and there was a small difference....... I had: <RESULTSET><xsl:attribute name="FOUND">1</xsl:attribute> <xsl:for-each select="Response/ITEMS/ITEM"> <ROW> <xsl:attribute name="MODID">0</xsl:attribute> <xsl:attribute name="RECORDID">1</xsl:attribute> Instead of: <RESULTSET FOUND=""> <xsl:for-each select="Response/ITEMS/ITEM"> <ROW MODID="" RECORDID=""> So thanks again for the help !! And I hope you're having a great weekend!
comment Posted August 6, 2011 Posted August 6, 2011 Actually, it shouldn't make a difference. <RESULTSET> <xsl:attribute name="FOUND">1</xsl:attribute> ... is the same as: <RESULTSET FOUND="1"> ... and Filemaker ignores the actual value when importing anyway.
Cabinetman Posted August 11, 2011 Author Posted August 11, 2011 HHhhuuummmmmmm ... Possibly I had something else wrong. I just know that when I switched it to the later .. <RESULTSET FOUND=""> .... no 0's or 1's it worked.
beverly Posted August 15, 2011 Posted August 15, 2011 Yes, Cabinetman. I always leave this blank. I don't know if it's ignored or not.
comment Posted August 15, 2011 Posted August 15, 2011 See the table at note #2 here: http://www.filemaker.com/11help/html/import_export.16.34.html#1029660
Cabinetman Posted August 16, 2011 Author Posted August 16, 2011 HHHHhhhuuuummmmm again ... LOL I'm not putting any blame or pointing fingers ... because this could be something I did all by myself .... but way back in the day ( couple of yrs ago) when i was first getting into needing this I had: <RESULTSET> <xsl:attribute name="FOUND">1</xsl:attribute> <xsl:for-each select="amz:ItemLookupResponse/amz:Items/amz:Item"> <ROW> <xsl:attribute name="MODID">0</xsl:attribute> <xsl:attribute name="RECORDID">1</xsl:attribute> in my code.... which I came to I think ... and I say I think ... with the help on Fenton and some others. Is this consider wrong or poor style? NOTE: That works fine for my basic imports......
comment Posted August 17, 2011 Posted August 17, 2011 It's not wrong, just unnecessarily verbose. Usually, you'd use xsl:attribute when the value needs to be calculated.
beverly Posted November 19, 2011 Posted November 19, 2011 or there is the attribute value template usage <http://www.dpawson.co.uk/xsl/sect2/N1575.html>
Recommended Posts
This topic is 5020 days old. Please don't post here. Open a new topic instead.
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 accountSign in
Already have an account? Sign in here.
Sign In Now