3 Replies Latest reply on Nov 26, 2009 1:49 AM by comment_1

    XML - working with Attributes and more than one Element of the same type

    goodhope

      Title

      XML - working with Attributes and more than one Element of the same type

      Post

      <!--  StartFragment  -->

      Hello,

       

      I've managed to successfully get a simple XML fileinto Filemaker. What I would now appreciate assistance on is in two areas:

       

       

      1. Some of the data that I'd like to work with isburied inside the element name in the form of attributes - how can I extractand use this (for instance: [CourtNumber Number="17022 and 17413" Year="2009"/]- here I'd like to use '17022 and 17413' and '2009').

       

       

      2. In some cases I have more than one instance of anelement in my XML file to import (such as the 'CompanyName' tag below).Sometimes there is only one, sometimes more. When I use my XSLT I only bring inthe first piece of text (AA Consultancy Limited) and lose the second.

       

      [Company]

      [CompanyName Class="Company"]AA CONSULTANCYLIMITED[/CompanyName]

      [CompanyName Class="Company"]BB CONSULTANCYLIMITED[/CompanyName]

      [/Company]

       

       

      I realise that I need to make amendments to my XSLT,but I'm struggling to know what to do here.  Can anyone offer some assistance on the correct syntax andcommands for the XSLT file.

       

      I’m defining all my XML elements inside the [Metadata]tag in my XSLT as:

       

      [FIELD NAME=”CompanyName” TYPE=”TEXT” EMPTYOK=”YES”MAXREPEAT=””/]

       

      then inside the ‘RESULTSET FOUND’ tag (again for allelements):

       

      [COL][DATA][xsl:value-of select=”(path in XMLfile)/CompanyName”/][/DATA][/COL]

      <!--  EndFragment  -->

        • 1. Re: XML - working with Attributes and more than one Element of the same type
          comment_1
            

          1. To retrieve an attribute, use the @ sign - see the example in your other thread, where the first field gets the Reference attribute of the <Notice> element.

           

          2. It depends, but normally you would import multiple elements into a related table (Companies, in your current example), using another stylesheet that creates a new record for each company.

          • 2. Re: XML - working with Attributes and more than one Element of the same type
            goodhope
              

            Thanks very much for you contributions - I'll see if I can put them to good use.

             

            One the multiple elements issue. I don't think I explained myself too well. The XML file I'm working with is a collection of Adverts for a particular newspaper. Most adverts will have for instance a heading (something like [Title] and [/Title]), then there will be any number of paragraphs of text (using tags as so: [Para][Text]This is the text for the first paragraph.[/Text][/Para] [Para][Text]This is the text for the second paragraph.[/Text][/Para] ). On import into Filemaker I'd either like to read all the 'paragraph' text into one field, or have multiple fields set up in the one record to except text (One record to be one advert).

             

            Thanks for any assistance on this - gratefully appreciated.

             

            Cheers Nick 

            • 3. Re: XML - working with Attributes and more than one Element of the same type
              comment_1
                

              It would be difficult to import them into separate fields, because you don't know how many paragraphs there will be. And it wouldn't be a good structure to have - regardless of the import issues.

               

              To import all paragraphs into a single field, replace:

              <COL><DATA><xsl:value-of select="Para/Text"/></DATA></COL>

              with:

              <COL><DATA>
              <xsl:for-each select="Para">
              <xsl:value-of select="Text"/>
              <xsl:value-of select="'&#13;'"/>
              </xsl:for-each>
              </DATA></COL>

               

              ---

              This could be improved by inserting the carriage return ('&#13;') conditionally after all paragraphs except the last one, but I did this in a hurry, so…