Skip to main content
Bedazzled532
Inspiring
February 27, 2024
Answered

Report Card using XML in InDesign

  • February 27, 2024
  • 2 replies
  • 2476 views

Hi,

I am preparing a report card for my client. Its their requirement that I do that using XML.

I have created a schema.xml file and students.xml file. The structure for both the files are same. Only difference is that students.xml file is loaded with data and schema.xml file is empty.

 

I created Indesign file and imported schema.xml file. Then I mapped the structure with the appropriate text frames. None of the textframes are linked. Then I mapped the styles with tags. So far all is fine.

 

Now I import the actual students.xml file. The problem starts here. First page popluates with the data perfectly but its not adding more pages. As per the students.xml there are 14 students data in it.

Data gets loaded in the structure pane but all that Indesign shows is Page 1 only.

 

I have attached sample idml file and both the schema file. What am I doing wrong ?

Plz help. 

 

Thanks

This topic has been closed for replies.
Correct answer Mario Fritsche

Hello,
InDesign and XML have not been best friends for years.
Take a look at the problem of whitespace. You can solve it with a script or you can use XSL. This ensures that the data comes in cleanly.
Here is an example of an XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"
  xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="no" media-type="test/>xml"/>
  <xsl:template match="/">
    <root>
      <xsl:apply-templates />
    </root>
  </xsl:template>
  <xsl:key name="groupKey" match="//students/record" use="student-name" />

  <xsl:template match="/students">
    <students>
      <xsl:for-each select="//students/record[count(. | key('groupKey', student-name)[1]) = 1]">
        <record>
          <student-name>
            <xsl:apply-templates select="student-name" />
            <xsl:text>&#13;</xsl:text>
          </student-name>
          <fathers-name>
            <xsl:apply-templates select="fathers-name" />
            <xsl:text>&#13;</xsl:text>
          </fathers-name>
          <class>
            <xsl:apply-templates select="class" />
            <xsl:text>&#13;</xsl:text>
          </class>
          <jan>
            <xsl:apply-templates select="jan" />
            <xsl:text>&#13;</xsl:text>
          </jan>
          <feb>
            <xsl:apply-templates select="feb" />
            <xsl:text>&#13;</xsl:text>
          </feb>
          <mar>
            <xsl:apply-templates select="mar" />
            <xsl:text>&#13;</xsl:text>
          </mar>
          <apr>
            <xsl:apply-templates select="apr" />
            <xsl:text>&#13;</xsl:text>
          </apr>
          <may>
            <xsl:apply-templates select="may" />
            <xsl:text>&#13;</xsl:text>
          </may>
          <jun>
            <xsl:apply-templates select="jun" />
            <xsl:text>&#13;</xsl:text>
          </jun>
          <jul>
            <xsl:apply-templates select="jul" />
            <xsl:text>&#13;</xsl:text>
          </jul>
          <aug>
            <xsl:apply-templates select="aug" />
            <xsl:text>&#13;</xsl:text>
          </aug>
          <sep>
            <xsl:apply-templates select="sep" />
            <xsl:text>&#13;</xsl:text>
          </sep>
          <oct>
            <xsl:apply-templates select="oct" />
            <xsl:text>&#13;</xsl:text>
          </oct>
          <nov>
            <xsl:apply-templates select="nov" />
            <xsl:text>&#13;</xsl:text>
          </nov>
          <dec>
            <xsl:apply-templates select="dec" />
            <xsl:choose>
              <xsl:when test="not(position()=last())">
                <xsl:text>&#13;</xsl:text>
              </xsl:when>
            </xsl:choose>
          </dec>
        </record>
      </xsl:for-each>
    </students>
  </xsl:template>
</xsl:stylesheet>


But first you have to adapt your InDesign. The text frames must be concatenated, otherwise everything is in the first text frame.

2 replies

Mario Fritsche
Mario FritscheCorrect answer
Legend
February 29, 2024

Hello,
InDesign and XML have not been best friends for years.
Take a look at the problem of whitespace. You can solve it with a script or you can use XSL. This ensures that the data comes in cleanly.
Here is an example of an XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"
  xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="no" media-type="test/>xml"/>
  <xsl:template match="/">
    <root>
      <xsl:apply-templates />
    </root>
  </xsl:template>
  <xsl:key name="groupKey" match="//students/record" use="student-name" />

  <xsl:template match="/students">
    <students>
      <xsl:for-each select="//students/record[count(. | key('groupKey', student-name)[1]) = 1]">
        <record>
          <student-name>
            <xsl:apply-templates select="student-name" />
            <xsl:text>&#13;</xsl:text>
          </student-name>
          <fathers-name>
            <xsl:apply-templates select="fathers-name" />
            <xsl:text>&#13;</xsl:text>
          </fathers-name>
          <class>
            <xsl:apply-templates select="class" />
            <xsl:text>&#13;</xsl:text>
          </class>
          <jan>
            <xsl:apply-templates select="jan" />
            <xsl:text>&#13;</xsl:text>
          </jan>
          <feb>
            <xsl:apply-templates select="feb" />
            <xsl:text>&#13;</xsl:text>
          </feb>
          <mar>
            <xsl:apply-templates select="mar" />
            <xsl:text>&#13;</xsl:text>
          </mar>
          <apr>
            <xsl:apply-templates select="apr" />
            <xsl:text>&#13;</xsl:text>
          </apr>
          <may>
            <xsl:apply-templates select="may" />
            <xsl:text>&#13;</xsl:text>
          </may>
          <jun>
            <xsl:apply-templates select="jun" />
            <xsl:text>&#13;</xsl:text>
          </jun>
          <jul>
            <xsl:apply-templates select="jul" />
            <xsl:text>&#13;</xsl:text>
          </jul>
          <aug>
            <xsl:apply-templates select="aug" />
            <xsl:text>&#13;</xsl:text>
          </aug>
          <sep>
            <xsl:apply-templates select="sep" />
            <xsl:text>&#13;</xsl:text>
          </sep>
          <oct>
            <xsl:apply-templates select="oct" />
            <xsl:text>&#13;</xsl:text>
          </oct>
          <nov>
            <xsl:apply-templates select="nov" />
            <xsl:text>&#13;</xsl:text>
          </nov>
          <dec>
            <xsl:apply-templates select="dec" />
            <xsl:choose>
              <xsl:when test="not(position()=last())">
                <xsl:text>&#13;</xsl:text>
              </xsl:when>
            </xsl:choose>
          </dec>
        </record>
      </xsl:for-each>
    </students>
  </xsl:template>
</xsl:stylesheet>


But first you have to adapt your InDesign. The text frames must be concatenated, otherwise everything is in the first text frame.

---Mario
Bedazzled532
Inspiring
February 29, 2024

@Mario Fritsche Thanks for the reply.

Where do I apply this XSL and how ?

By concatenation you mean threading ?

Suppose I 100 records in XML, do I have to add 100 pages first and link all of them ? I am trying this XML thing since 2 weeks and its all going above my head. 

Thanks for your help. I have to learn his XML Indesign thing. Maybe its difficult for me now but eventually it will become easier.

Mario Fritsche
Legend
February 29, 2024

Yes, threading.

Download the XSLT file here and your example InDesign file: https://www.dropbox.com/scl/fo/jyvel0enc3caqh7bx4g8v/h?rlkey=i8u487ee1n1shxe4utrjlottd&dl=0
Then import the XML (select the option "Show XML import options" in the window). Then select the downloaded XSLT in the Apply SXLT dialog.

https://helpx.adobe.com/indesign/using/importing-xml.html

---Mario
Bedazzled532
Inspiring
February 29, 2024

Any suggestions ? Anyone?