xsl-list
[Top] [All Lists]

RE: Paragraphs in Word XML

2006-01-06 01:56:47
Hi again,

To follow up this thread I'll tell you how I finally succeeded in this. As 
Michael said it was a tough one.

I did the transformation in two steps. If I understand correctly it could not 
be done with plain XSLT 1.0 but libsxlt has the <xsl:document> element from 
XSLT 1.1 that I needed and this is available in other engines too.

1. First I created a temporary file as this:

<xsl:document href="tmp.xml">
<dict>
  <entry>
 <xsl:call-template name="raport" /> 
  </entry>
</dict>
</xsl:document>

2. Here I created the result without any <p> elements but with 
<w:pPr>
   <w:pStyle w:val="TableHeader"/>
</w:pPr>

(Paragraph style definition) at the beginning of every paragraph

3. Then I read the data into the document using

 <xsl:apply-templates select="document('tmp.xml')"/>


4. In this I used transformations using method by David Carlisle from 

http://www.biglist.com/lists/xsl-list/archives/200510/msg00089.html

To add the <p> element in the right places.
I could not solve without using tmp.xml. 

So great thanks for Michael and David and for this great list.

Regards
Kaarle


-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com] 
Sent: 4. tammikuuta 2006 17:06
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Paragraphs in Word XML

This is a tough one but similar problems have been solved on this list before!

I think the design in outline is this: if you encounter a table that has a 
break element within it, you need to apply a template/function that splits it 
into two: everything before the break, and everything after the break; you then 
apply the same processing recursively to "everything after the break" in case 
there are multiple breaks.

The processing is a template rule that takes the break element as a parameter. 
When processing an element that is an ancestor of the break element, create a 
shallow copy of yourself containing deep copies of all your pre-break children; 
then apply templates recursively to the child that's an ancestor of the break 
element, then create a shallow copy of yourself containing deep copies of all 
your post-break children.

Hope that makes sense, I don't have time to translate it into code!

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Kaila Kaarle [mailto:Kaarle(_dot_)Kaila(_at_)nice(_dot_)fi]
Sent: 04 January 2006 13:52
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Paragraphs in Word XML

Hello,

I have an xml file containing the data for my genealogical report. It 
contains table elements and section elements and within sections there 
are person - relation and notices elements.
Notices elements contain notice elements with information such as 
birth dates and places but also long texts about what the person did. 
The text is divided into para elements and some of them must be 
written into separate paragraps in the output.

Word XML requires that <body> element contains <p>
(paragraph) elements. When I use XSTL to create my document I would 
usually transform one section in my XML into a <p> element in Word 
XML. But if the text contains paragraph marks I need to fininsh the 
current Word paragraph and start a new one (with a different style) 
but I don't know if I can do that in XSLT.

I'll add an example at the end of this message of my xml.

My xml looks like this: All of it should go to one pargraph if the 
<notice tag="NOTE"> would not contain the <para type="NEW"> element. 
The rest of the text should go to the second paragraph.

How can I split the text in the example into two different elements on 
output???
Regards
Kaarle

 <tables>
    <table number="1">
      <section type="MAIN" gen="1">                 
        <person sex="M" unitid="I1" source="1">
          <name>
            <givenname>Paavo</givenname>
            <surname>Kaila</surname>
          </name>
          <notices>
            <notice tag="BIRT" text="Syntynyt">
              <date value="18840413">13.04.1884</date>
              <place name="Vimpeli">Vimpeli</place>
            </notice>
            <notice tag="DEAT" text="Kuollut">
              <place name="Lappeenranta">Lappeenranta</place>
            </notice>
            <notice tag="OCCU">
              <para>Bonde</para>
              <place name="Esse">Esse</place>
            </notice>
            <notice tag="NOTE">
              <para>Paavo oli isäni isä. Hän meni Evan kanssa 
naimisiin mutta oli hänellä pari kolme muutakin vaimoa. Heitä en ole 
tavannut vaikka viimeinen kuoli vasta muutama vuiosi sitten.
</para>
              <para type="NEW">Lisäsin tähän vielä tällaisen toisen 
tekstikappaleen. Word-xml testi on nyt testattavana ja siinäkin 
pitäisi saada kappaleet paikoilleen. Muuten homma ei oikein suju. 
Myöskin olisi hyvä jos tämä jatkuisi useammalle riville. Ehkä se jo on 
ohittanut ekan rivin loppusarakkeen.</para>
            </notice>
            <notice tag="PHOT">
              <media name="P1R7.jpg" number="1">Tämä on Paavo</media>
            </notice>
          </notices>
          <relation type="SPOU" number="1" source="2">
            <event type="MARR">
              <date value="1907">1907</date>
              <place name="Tammerfors">Tammerfors</place>
            </event>
            <person sex="F" unitid="I2">
              <name>
                <givenname>Eva Charlotta</givenname>
                <surname>Koskinen</surname>
              </name>
              <notices>
                <notice tag="NAME">
                  <name>
                    <givenname>Eva Charlotta</givenname>
                    <surname>Kaila</surname>
                  </name>
                </notice>
                <notice tag="BIRT" text="Syntynyt" source="3">
                  <date value="18920422">22.04.1892</date>
                  <place name="Tammela">Tammela</place>
                </notice>
                <notice tag="DEAT" text="Kuollut">
                  <date value="19640406">06.04.1964</date>
                  <place name="Helsinki">Helsinki</place>
                </notice>
              </notices>
            </person>
          </relation>
        </person>
      </section>
   </table>
</tables>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>