0 Replies Latest reply on Feb 22, 2011 6:20 PM by tomDalton8181

    XSL for a XML export of related fields

    tomDalton8181

      Title

      XSL for a XML export of related fields

      Post

      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