xsl-list
[Top] [All Lists]

Re: [xsl] Merging changes via ID

2009-06-22 17:37:48
Lech R. schrieb am 22.06.2009 um 18:13:24 (+0100):
Or maybe I'm just tired.

Hi Lech,

in that case, more pivo is required !!!

I want the new file to reflect the structure of the updated, English
file and have the text content of the translated one. The XML files
are derived from Docbook.

Okay, I guess the structure is the sequence of /*/*[(_at_)xml:id] - so
everything with an ID at level 2.

So, to begin, I've created the following:

  <xsl:template match="*[(_at_)xml:id]">
    <xsl:copy-of
select="document('doc2.xml')//*[(_at_)xml:id=document('doc1.xml')//@xml:id]"/>
  </xsl:template>

Note there is a nifty idiom: document('bla.xml#gurke') selects the
element node with ID "gurke" out of document "bla.xml".

Also, the id() function might come in handy.

My worries:
the recursion is from top to bottom, so what if there are changes
below and the tempate matches the whole tree at the top?
It matched on ID but what about the changes for inline elements below
block level that don't have an ID? Would it make processing more
simple were I to generate IDs for them or should I process and match
them as descendant of a given ID of a block?
Other worries such as removed, added element, I've already taken care
of those.

I'm not sure I understand all of this. Take a look at the following,
maybe this is helpful, maybe not:

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

  <xsl:param name="doc2" select="'lech-xmlid.pl.xml'"/>

  <!-- elements with ID below document element -->
  <xsl:template match="/*/*[(_at_)xml:id]">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="document( concat( $doc2, '#', @xml:id))"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Note this leaves an unmatched <section xml:id="s02"/> in the output,
If you don't want that, it could be avoided quite easily.

<?xml version="1.0"?>
<article xmlns="http://docbook.org/ns/docbook"; version="5.0"
xml:id="SAMPLE_EN">
    <info xml:id="intro"><info xml:id="intro">                                  
                  
        <title>Wprowadzenie do Docbook</title>
    </info></info>
    <section xml:id="s01"><section xml:id="s01">
        <title>Formatowanie i Obrazki</title>
        <para>Oto przyklad ze &lt;oXygen/&gt; moze byc uzwany do
edycji dokumentow zgodnych z dockbookx.dtd.</para>
        <para>Aby obejrzec te instrukcje w przegladarce WWW, wybierz
nastepujacy scenariusz transformacji:
            <code>Docbook HTML</code>.
        </para>
    </section></section> 
    <section xml:id="s02"/>
    <section xml:id="s04"><section xml:id="s04"><title>Przyklad
zagniezdzania</title>
        <para>Aby zilustrowac problemy z zagniezdzaniem.</para>
    </section></section>                                   
</article>

Best,

Michael Ludwig

--~------------------------------------------------------------------
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>