Jump to content

Matching elements


DanBrill

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

Recommended Posts

Hey,

I've got some FileMaker xml output (FMPDSORESULT style). I have a list of people and their phone numbers...


...

      <CriticalGroupMembers.PersonName>

         <DATA>Bergman, Carrolyn</DATA>

         <DATA>Brill, Daniel</DATA>

         <DATA>Brill, Helen</DATA>

      </CriticalGroupMembers.PersonName>



      <CriticalGroupMembers.PersonHomePhone>

         <DATA>999-999-9999</DATA>

         <DATA>320-999-5644</DATA>

         <DATA>716-999-4844</DATA>

      </CriticalGroupMembers.PersonHomePhone>

...





I want to transform this with an xslt so that my result matches each person with their phone number.  Something like









<ap:Topic>

   <ap:SubTopics>

      <ap:Topic>

         <ap:SubTopics>

            <ap:Topic>

               <ap:Text PlainText="999-999-9999">

                  <ap:Font />

               </ap:Text>

            </ap:Topic>

         </ap:SubTopics>



         <ap:Text PlainText="Bergman, Carrolyn">

            <ap:Font />

         </ap:Text>

      </ap:Topic>



      <ap:Topic>

         <ap:SubTopics>

            <ap:Topic>

               <ap:Text PlainText="320-999-5644">

                  <ap:Font />

               </ap:Text>

            </ap:Topic>

         </ap:SubTopics>



         <ap:Text PlainText="Brill, Daniel">

            <ap:Font />

         </ap:Text>

      </ap:Topic>



      <ap:Topic>

         <ap:SubTopics>

            <ap:Topic>

               <ap:Text PlainText="716-999-4844">

                  <ap:Font />

               </ap:Text>

            </ap:Topic>

         </ap:SubTopics>



         <ap:Text PlainText="Brill, Helen">

            <ap:Font />

         </ap:Text>

      </ap:Topic>





The problem is that I can't get each person's phone number to match their record.  The way it is looping, the first phone number in the list gets applied to every person.



This is the xslt code I'm using...





<ap:Topic>

   <ap:SubTopics>

      <xsl:for-each select="fmp:CriticalGroupMembers.PersonName/fmp:DATA">

         <ap:Topic>

            <ap:SubTopics>

               <ap:Topic>

                  <ap:Text>

                     <xsl:attribute name="PlainText">

                        <xsl:value-of select="../../fmp:CriticalGroupMembers.PersonHomePhone/fmp:DATA" />

                     </xsl:attribute>



                     <ap:Font />

                  </ap:Text>

               </ap:Topic>

            </ap:SubTopics>



            <ap:Text>

               <xsl:attribute name="PlainText">

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

               </xsl:attribute>



               <ap:Font />

            </ap:Text>

         </ap:Topic>

      </xsl:for-each>

   </ap:SubTopics>

</ap:Topic>



I know the problem is in the way the loop is set up. How do I set it up so that the first time through it matches the first person to the first phone number, the second time it matches the second person to the second phone number, and so on?

I've attached the full xml and xslt file so you can see them in all their glory.

Thanks for any insight,

Dan

CriticalGroupsWithPhone.zip

Link to comment
Share on other sites

An example with 3 persons and there email :

the fmp->xml output


<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">

    <RESULTSET FOUND="1">

        <ROW MODID="1" RECORDID="1">

            <COL>

                <DATA>Nagy</DATA>

                <DATA>Durant</DATA>

                <DATA>Javaux</DATA>

            </COL>

            <COL>

                <DATA>[email protected]</DATA>

                <DATA>[email protected]</DATA>

                <DATA>[email protected]</DATA>

            </COL>

        </ROW>

    </RESULTSET>

</FMPXMLRESULT>





the xsl file 





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

<xsl:stylesheet exclude-result-prefixes="fmp" version="1.1"

    xmlns:fmp="http://www.filemaker.com/fmpxmlresult" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

    <xsl:template match="fmp:FMPXMLRESULT">

        <breves>

            <xsl:apply-templates select="fmp:RESULTSET/fmp:ROW"/>

        </breves>

    </xsl:template>

    <xsl:template match="fmp:RESULTSET/fmp:ROW">

            <auteurs>

                <xsl:apply-templates select="fmp:COL[1]/fmp:DATA"/>

            </auteurs>

    </xsl:template>

    <xsl:template match="fmp:COL[1]/fmp:DATA">

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

        <auteur>

            <nom>

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

            </nom>

            <mail>

                <xsl:value-of select="ancestor::fmp:ROW/fmp:COL[2]/fmp:DATA[position()=$pos]"/>

            </mail>

        </auteur>

    </xsl:template>

</xsl:stylesheet>





the result :





<?xml version="1.0" encoding="utf-8"?>

<breves>

   <auteurs>

      <auteur>

         <nom>Nagy</nom>

         <mail>[email protected]</mail>

      </auteur>

      <auteur>

         <nom>Durant</nom>

         <mail>[email protected]</mail>

      </auteur>

      <auteur>

         <nom>Javaux</nom>

         <mail>[email protected]</mail>

      </auteur>

   </auteurs>

</breves>

I hope this help you.

Link to comment
Share on other sites

This topic is 7295 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.