Jump to content

XML + XSL performs import but doesn't loop


Quito

This topic is 616 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi, fmforums team,

I have an xml with two components: Descriptor and Substance. One Descriptor can contain many substances, yet, when I import using the Substance.xsl, it imports only the first substance for each Descriptor. How do I tell the .xsl to import the substances recursively?

I'm including the following files:

.xsl

.xml

.dtd (empty)

.fmp12

Thank you,Pharmacological action.zip

Daniel

Link to comment
Share on other sites

If you want the import to create a record for each substance, then you must tell the stylesheet to create a ROW for each Substance. Your stylesheet creates a ROW:

<xsl:for-each select="PharmacologicalActionSet/PharmacologicalAction/PharmacologicalActionSubstanceList">

and then does:

<xsl:value-of select="Substance/RecordUI"/>

which gets the value from the first Substance child of the current PharmacologicalActionSubstanceList.

I would suggest you try it this way:

<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="/PharmacologicalActionSet">
	<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
		<METADATA>
			<FIELD NAME="DescriptorUI"/>
			<FIELD NAME="RecordUI"/>
			<FIELD NAME="String"/>
		</METADATA>
		<RESULTSET>
			<xsl:for-each select="PharmacologicalAction">
				<xsl:variable name="descriptorUI" select="DescriptorReferredTo/DescriptorUI"/>
				<xsl:for-each select="PharmacologicalActionSubstanceList/Substance">
					<ROW>
						<COL>
							<DATA>
								<xsl:value-of select="$descriptorUI"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="RecordUI"/>
							</DATA>
						</COL>
						<COL>
							<DATA>
								<xsl:value-of select="RecordName/String"/>
							</DATA>
						</COL>
					</ROW>
				</xsl:for-each>
			</xsl:for-each>
		</RESULTSET>
	</FMPXMLRESULT>
</xsl:template>

</xsl:stylesheet>

 

---
P.S. Next time please reduce your example to a reasonable size.

 

 

  • Thanks 1
Link to comment
Share on other sites

Wow, @comment!

It worked beautifully! Sorry about the filesize. I actually picked the smallest .xml, as they are usually closer to a GB.

All the very best,
Daniel

Link to comment
Share on other sites

This topic is 616 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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