Skip navigation
prowebphoneapp
Currently Being Moderated

Transforming xml with xslt

Sep 13, 2013 5:36 AM

Tags: #import_xml_to_indesign

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.

 
Replies
  • Currently Being Moderated
    Sep 13, 2013 7:58 AM   in reply to prowebphoneapp

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

     

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 13, 2013 11:46 AM   in reply to prowebphoneapp

    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 ;-)

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 16, 2013 8:41 AM   in reply to prowebphoneapp

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points