5 Replies Latest reply on Sep 17, 2013 5:49 AM by prowebphoneapp

    Transforming xml with xslt

    prowebphoneapp

      Hi,

       

         i need to create phonebook with 5000 persons, every person has name, surnam,

         address, city and few phone numbers, all users are stored in database and

         i plan to create xml file with format like this.

       

         <person>

           <name>Mark</name>

           <surname>Popovic</surname>

           <address>Cvijetna bb</address>

           <city>Dubrovnik</city>

           <contacts>

                <phone>023023920</phone>

                <phone>093209320</phone>

           </contacts>

         </person>

       

      <person>

           <name>Danilo</name>

           <surname>Popovic</surname>

           <address>Makb2b</address>

           <city>Treviso</city>

           <contacts>

                <phone>023023920</phone>

                <phone>093209320</phone>

           </contacts>

         </person>

       

         etc.

       

         The problem is i don't know how to style this XML with XSLT to look like picture which you can download from here

         http://www.sendspace.com/file/7sqdgi.

        • 1. Re: Transforming xml with xslt
          MW Design Level 4

          Please simply post the image or use a truly public upload service like dropbox.com or wikisend.com

           

          Mike

          • 2. Re: Transforming xml with xslt
            JoaoCP Level 2

            Based on the image, it seems that your catalog has two patterns of entries:

             

            * if there's only one phone number:

            Name<SPACE>Surname<TAB>Phone<RETURN>

            Address<SLASH>City<RETURN>

             

            * if there are more than one phone number:

            Name<SPACE>Surname<RETURN>

            Address<SLASH>City<RETURN>

            Phone<RETURN>

            Phone<RETURN>

            ...

             

             

            Below you have an XSLT that handles these variants:

             

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

            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

            <xsl:output method="xml" encoding="utf-8" indent="yes"/>

             

            <xsl:template match="root">

                <xsl:copy>

                    <xsl:for-each select="(//person)">

                        <xsl:copy>

                        <xsl:choose>

                            <xsl:when test="count(contacts/phone) &gt; 1">

                                <namewithoutphone>

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

                                    <xsl:text> </xsl:text>

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

                                    <xsl:text>

            </xsl:text>

                                </namewithoutphone>

                                <addresspluscity>

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

                                    <xsl:text>/</xsl:text>

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

                                    <xsl:text>

            </xsl:text>

                                </addresspluscity>

                                <xsl:for-each select="(contacts/phone)">

                                    <phone>

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

                                    <xsl:text>

            </xsl:text>

                                    </phone>

                                </xsl:for-each>

                            </xsl:when>

                            <xsl:otherwise>

                                <nameplusphone>

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

                                    <xsl:text> </xsl:text>

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

                                    <xsl:text>&#9;</xsl:text>

                                    <xsl:value-of select="contacts/phone" />

                                    <xsl:text>

            </xsl:text>

                                </nameplusphone>

                                <addresspluscity>

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

                                    <xsl:text>/</xsl:text>

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

                                    <xsl:text>

            </xsl:text>

                                </addresspluscity>

                            </xsl:otherwise>

                        </xsl:choose>

                   </xsl:copy>

                   </xsl:for-each>

                </xsl:copy>

            </xsl:template>

             

            </xsl:stylesheet>

             

             

            It assumes that the directory has these paragraph styles:

             

            one for the NameSurname case

            one for the NameSurnamePhone case

            one for the adress/city

            one for the Phone case

             

            Obviously, you can (or must) adapt the XSLT and/or your XML settings for your needs. For instance, if you don't need two different paragraph styles for the  Name/Surname and NameSurnamePhone lines, you can either use the same tag in the XSLT or keep the XSLT as is and map both tags to the same paragraph style in InDesign.

             

            The sample stylesheet and XML files are stored here:

             

            https://dl.dropboxusercontent.com/u/106093/prowebphoneapp_sample_files.zip

             

            They won't be forever in this place, so I ask you to download them a soon as you can.

             

            By the way, please follow MW Design's advice and, next time, insert the image direct in your post using the camera icon in the head of the message editor. That upload service you used is awful ;-)

            • 3. Re: Transforming xml with xslt
              prowebphoneapp Level 1

              Hi,

               

                 sorry you for late reply, thank you, this is ok for the beginning but i need more cusomisation

                 like static text and static images. Also, as i am not designer but software developer and i didin't

                 understand you well, do i need paragraph styles in order to set name/surname/numbers bold?

                 Can i do that in xslt? 

              • 4. Re: Transforming xml with xslt
                MW Design Level 4

                As a software designer, you need to grasp what the provided xslt is doing and alter it to your purposes.

                 

                The paragraph styles in InDesign can be bold, you don't need to use xslt for that. If there will be a mix of normal text and an attribute like bold, you can create character styles and use the xslt to mark the xml accordingly.

                 

                Google how to include the images as http references in the XML. That will then link them and once the XML is in ID, you will see them.

                 

                Beyond that, you need to be more specific and provide an example of what you really need. One way to learn of ID's XML is to first create a single example record. Then export that to XML and study the output.

                • 5. Re: Transforming xml with xslt
                  prowebphoneapp Level 1

                  Can you explain me this lines:

                  <xsl:when test="count(contacts/phone) &gt; 1"> - i understand that you counting phonesm, but i don't understand;

                  this syntax &gt; 1. Also <xsl:text>&#9;</xsl:text> this line, what &#9 means?;

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

                  And please can you explain me nameplusphone paragraph style, how did you add dots?

                   

                  Thank you.