Jump to content

XSL for a XML export of related fields


tom_ray
 Share

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

Recommended Posts

  • Newbies

I hope someone can help me. I've spent about 12 hours trying to figure this out and I'd pull out my hair if I had any.

I have two tables (Category) and (Images) (*See picture of tables.) and my XML output should look like this....

<root>

<category id="1" title="toys" name="toys" parent_id="-1">

_____<images>

__________<image id="1" title="ball" colorize="true" imageUrl="domain/ball.jpg" category_id="1" description="ball, toy" />

__________<image id="2" title="car" colorize="true" imageUrl="domain/car.jpg" category_id="1" description="car, toy" />

_____</images>

</category>

<category id="2" title="clothes" name="clothes" parent_id="-1">

_____<images>

__________<image id="3" title="shirt" colorize="true" imageUrl="domain/shirt.jpg" category_id="2" description="red, shirt" />

__________<image id="4" title="pants" colorize="true" imageUrl="domain/pants.jpg" category_id="2" description="pants, blue" />

_____</images>

</category>

</root>

This is my XSL (that doesn't work)....

<?xml version='1.0' encoding='UTF-8' ?>

<xsl:stylesheet version='1.0'

xmlns:xsl='http://www.w3.org/1999/XSL/Transform'

xmlns:fm="http://www.filemaker.com/fmpdsoresult"

exclude-result-prefixes="fm">

<xsl:output version='1.0' encoding='UTF-8' indent='yes' method='xml' />

<xsl:template match="/">

<xsl:for-each select="fm:FMPDSORESULT/fm:ROW">

<category>

<xsl:attribute name="ID"><xsl:value-of select="fm:ID"/></xsl:attribute>

<xsl:attribute name="title"><xsl:value-of select="fm:title"/></xsl:attribute>

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

<xsl:attribute name="parent_id"><xsl:value-of select="fm:parent_id"/></xsl:attribute>

<images>

<xsl:for-each select="fm:ID/fm:DATA">

<xsl:variable name="pos" select="position()"/>

<image>

<xsl:attribute name="ID"><xsl:value-of select="."/></xsl:attribute>

<xsl:attribute name="imageTITLE"><xsl:value-of select="../../fm:imageTITLE/fm:DATA[$pos]"/></xsl:attribute>

</image>

</xsl:for-each>

</images>

</category>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

--------------------------------------------------------

ANY IDEAS? Any help will be much appreciated!!

-TOM

xsl.png

Link to comment
Share on other sites

  • Newbies

Why don't you attach your raw XML output, to make it easier for us? Also explain what exactly "doesn't work"?

It works for the categories, but it is missing each category's related images. The output I'm currently getting would look like this...

<root>

<category id="1" title="toys" name="toys" parent_id="-1">

<images>

</images>

</category>

<category id="2" title="clothes" name="clothes" parent_id="-1">

<images>

</images>

</category>

</root>

Link to comment
Share on other sites

The first problem is that you are not exporting any child (image) fields.

The other issue is that XML is case-sensitive: "imageTITLE" is not the same as "ImageTITLE".

I also see a lot of unprintable characters in your stylesheet - this was throwing errors in my test application.

Finally, you have a field named ID in both tables - so it would be better to refer to the "other" ID for the loop (not critical, though).

image-categories.zip

Link to comment
Share on other sites

  • Newbies

You have made my day! or week. THANK YOU.

I'm obviously a hack and this was also the first time I was ever exposed to XSL and even my XML knowledge is scant. I found very little detailed information specifically about XSL as it pertains to FileMaker exports ...until I found this forum.

If I need to hire a qualified consultant ...I know where to look.

Thanks Again,

Tom

Link to comment
Share on other sites

This topic is 4367 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
 Share

×
×
  • Create New...

Important Information

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